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
| /** | |
| * @param {string} S | |
| * @return {string} | |
| * "ab-cd" should become "dc-ba" | |
| */ | |
| var reverseOnlyLetters = function(S) { | |
| let stack = []; | |
| let resultArr = []; | |
| let letters = /^[A-Za-z]+$/; | |
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
| /** | |
| * @param {string} s | |
| * @return {string} | |
| * "Let's take LeetCode contest" printed as "s'teL ekat edoCteeL tsetnoc" | |
| */ | |
| var reverseWords = function(s) { | |
| let sentence = []; | |
| let word = []; | |
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
| /** | |
| * @param {string} s | |
| * @return {string} | |
| * "the sky is blue" should be printed as "blue is sky the" | |
| */ | |
| var reverseWords = function(s) { | |
| let strArray = s.split(' '); | |
| let result = [] | |
| let temp; |
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
| var hasCycle = function(head) { | |
| if (head === null) return false; | |
| if (head.next === null) return false; | |
| let slow = head; | |
| let fast = head.next; | |
| while(fast !== null && fast.next !== null){ |
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
| /** | |
| * @param {number[]} nums | |
| * @return {number} | |
| */ | |
| var maxSubArray = function(nums) { | |
| let globalMax = nums[0]; | |
| let localMax = nums[0]; | |
| for(let i=1;i<nums.length;i++) { | |
| localMax = Math.max(localMax+nums[i], nums[i]) |
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
| /** | |
| * @param {number[]} nums | |
| * @param {number} val | |
| * @return {number} | |
| */ | |
| var removeElement = function(nums, val) { | |
| let slow=0; | |
| for(let fast = 0; fast < nums.length; fast++) { |
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
| var trap = function(height) { | |
| let left_max = []; | |
| let right_max = []; | |
| let rainWaterUnits = 0; | |
| let n = height.length; | |
| left_max[0] = height[0] | |
| for(let i=1;i<n;i++) { | |
| left_max[i] = Math.max(height[i], left_max[i-1]); |
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
| var lengthOfLongestSubstring = function(s) { | |
| let visited = {}; | |
| let maximum = 0; | |
| let i = 0; | |
| for(let j=0;j<s.length;j++) { | |
| if(visited[s.charAt(j)] !== undefined) { | |
| i = Math.max(i, visited[s.charAt(j)]) | |
| } |
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
| var removeDuplicates = function(nums) { | |
| if(nums.length === 0) return 0; | |
| let slow = 0; | |
| for(let fast = 0; fast < nums.length; fast++) { | |
| if(nums[slow] !== nums[fast]){ | |
| slow++; | |
| nums[slow] = nums[fast] |
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
| /** | |
| * Definition for singly-linked list. | |
| * function ListNode(val) { | |
| * this.val = val; | |
| * this.next = null; | |
| * } | |
| */ | |
| /** | |
| * @param {ListNode} head | |
| * @param {number} n |
NewerOlder