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
| //Determine whether an integer is a palindrome. Do this without extra space. | |
| var isPalindrome = function (x) { | |
| if (x < 0) { | |
| return false; | |
| } | |
| //何桁で割ったら、1桁になるか | |
| var div = 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
| //Reverse digits of an integer | |
| //Given x = 123, return 321 | |
| //Given x = -123, return -321 | |
| var reverse = function(x) { | |
| var lastDigit = 0, | |
| result = 0, | |
| isNeg = true; | |
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
| // Given an unsorted integer array, find the first missing positive integer | |
| // For example, | |
| // Given [1, 2, 0], return 3. | |
| // Given [3, 4, -1, 1], return 2. | |
| var firstMissingPositive = function(A){ | |
| var i = 0; |
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 createMapping = function(numbers) { | |
| var mapping = {}, | |
| size = numbers.length; | |
| for (var i = 0; i < size; i++) { | |
| mapping[numbers[i]] = i; | |
| } | |
| return mapping; |
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
| /* | |
| Find all unique triplets in the array which gives the sum of 0. | |
| a + b + c = 0; | |
| [-1, 0, 1, 2, -1, -4] ==> [[-1, 0, 1], [-1, -1, 2]]; | |
| */ | |
| var temp = [-1, 0, 1, 2, -1, -4]; |
NewerOlder