Skip to content

Instantly share code, notes, and snippets.

@rohanjai777
Last active September 12, 2023 18:11
Show Gist options
  • Save rohanjai777/e9912ce6396be3336f4a87f83921f52b to your computer and use it in GitHub Desktop.
Save rohanjai777/e9912ce6396be3336f4a87f83921f52b to your computer and use it in GitHub Desktop.
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