code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

Largestelement

/**
 *
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

class LargestElement {

  static int func(int[] nums) {
    int result = 0;
    for (int i = 1; i < nums.length; i++) {
      if(nums[i] > nums[result]){
        result = i;
      }
    }
    return result;
  }

  public static void main(String args[]) {
    int[] nums = {10, 20, 30, 40};
    int result = func(nums);
    System.out.println(result);
  }
}

Created 2021-10-26T03:12:44+01:00, updated 2021-10-26T19:15:26+01:00 · History · Edit