Last active
September 12, 2023 18:11
-
-
Save rohanjai777/e9912ce6396be3336f4a87f83921f52b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int max1 = nums[0]; //first max | |
int max2 = 0; //second max | |
for(int i=1;i<nums.length;i++){ | |
if(nums[i]>max1){ | |
max2 = max1; | |
max1 = nums[i]; //copy the first max to second max | |
}else if(nums[i]>max2){ | |
max2 = nums[i]; //second max | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment