Created
January 17, 2018 14:13
-
-
Save s4553711/c5d2b30a14beaf1de04a4b16651ac3d1 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
class Solution { | |
public: | |
int dominantIndex(vector<int>& nums) { | |
int maxi = -1, seci = -1; | |
for(int i = 0; i < nums.size(); i++) { | |
// cout << "b: i: " << i << " m: " << maxi << ", s: " << seci << endl; | |
if (nums[i] > nums[maxi]) { | |
int tmp = maxi; | |
maxi = i; | |
seci = tmp; | |
} else if (nums[i] > nums[seci]) { | |
seci = i; | |
} | |
// cout << "a: i: " << i << " m: " << maxi << ", s: " << seci << endl; | |
} | |
// cout << "maxi: " << maxi << endl; | |
// cout << "seci: " << seci << endl; | |
if (maxi == -1) return -1; | |
return nums[maxi] >= 2 * nums[seci] ? maxi : -1; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment