Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rezaramadhanirianto/c76c09d27175cd2b6d32802df6b9bc4e to your computer and use it in GitHub Desktop.

Select an option

Save rezaramadhanirianto/c76c09d27175cd2b6d32802df6b9bc4e to your computer and use it in GitHub Desktop.
long sum = 0, max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
for(int num: nums) sum += num;
for(int num: nums){
max = Math.max(max, sum - num);
min = Math.min(min, sum - num);
}
// return max & min
return new int[]{max, min};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment