We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The javascript version is exceeding time limit for longer list. Perhaps you may refer to following java code to develop a javascript version.
public List<List<Integer>> threeSum(int[] nums) { List<Integer> list; List<List<Integer>> retList = new LinkedList<>(); Arrays.sort(nums); for( int i = 0; i < nums.length && nums[i] <= 0; i++){ if( i > 0 && nums[i] == nums[i-1]) continue; int sum = (-1)*nums[i], front = i + 1, behin = nums.length - 1; while( front < behin ) if( nums[front] + nums[behin] > sum) behin--; else if( nums[front] + nums[behin] < sum) front++; else{ list = new LinkedList<Integer>(); list.add(nums[i]); list.add(nums[front]); list.add(nums[behin]); retList.add(list); while( front<behin && nums[front]==nums[front+1]) front++; while( front<behin && nums[behin]==nums[behin-1]) behin--; front++; behin--; } } return retList; }
The text was updated successfully, but these errors were encountered:
thanks, it's done via. https://github.com/hanzichi/leetcode/blob/master/Algorithms/3Sum/3sum.js
Sorry, something went wrong.
No branches or pull requests
The javascript version is exceeding time limit for longer list.
Perhaps you may refer to following java code to develop a javascript version.
The text was updated successfully, but these errors were encountered: