same idea. But I use 2 helpers to find the left and right boundaries.
Vick.Chen
@Vick.Chen
Posts made by Vick.Chen

RE: Clean iterative solution with two binary searches (with explanation)

RE: My O(n) solution using a stack
Similar idea as mine, but better than mine :)
I use char Stack instead of int Stack.
It leads I have to use another temp Stack to store information for valid parentheses. 
RE: Share my O(n) time solution
@GoldenalCheese
Let's discuss the worst case:
#1 take "1" n to find the index for swapping
#2 take another "1" n to to find the next bigger number
#3 take "1" step to swipe
#4 take "1/2" n to reverse sort the tail array.
The total O is n+n+1+n/2 = 2.5n +1 ~= O(n)And here's my own code, same idea, but less lines
public void NextPermutation(int[] nums) { int swapi = 0; for(int i = nums.Length  2; i >= 0 && swapi == 0; i) { if(nums[i] < nums[i + 1]) { for(int k = nums.Length  1; k >= i  1 && swapi == 0; k) { if(nums[k] > nums[i]) { int temp = nums[k]; nums[k] = nums[i]; nums[i] = temp; swapi = i + 1; } } } } //I'm lazy to write the funtion for swipe tail, //so the default sort is n*lgn, but you can write swipe function to reduce it to O(n/2) Array.Sort(nums, swapi, nums.Length  swapi); }

RE: 7ms java code win over 100%
@rikimberley said in 7ms java code win over 100%:
threeSumForFourSum
nice details about throwing impossibles cases out!

I think this should be marked as Easy
It's very easy to figure it out as soon as you understand what's Roman Number.
And here's my common solutionpublic string IntToRoman(int num) { string rs=""; int[] vals = {1000, 500, 100, 50, 10, 5, 1}; char[] chars = {'M', 'D', 'C', 'L', 'X', 'V', 'I'}; for(int i = 0; i < vals.Length && num > 0 ; i+=2) { int cur = num / vals[i]; if(cur == 0) { num = num % vals[i]; continue; } if(cur < 4) { while(cur > 0) { rs += chars[i].ToString(); cur; } } else if(cur == 4) { rs += chars[i].ToString() + chars[i  1].ToString(); } else if(cur < 9) { rs += chars[i  1].ToString(); while(cur  5 > 0) { rs += chars[i].ToString(); cur; } } else if(cur == 9) { rs += chars[i].ToString() + chars[i  2].ToString(); } num = num % vals[i]; } return rs; }