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 | |
| * @return {ListNode} |
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 {boolean} | |
| */ | |
| const reference = { | |
| '(': ')', | |
| '{': '}', | |
| '[': ']', | |
| }; |
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
| //input string | |
| //output number | |
| // I can be placed before V (5) and X (10) to make 4 and 9. | |
| // X can be placed before L (50) and C (100) to make 40 and 90. | |
| // C can be placed before D (500) and M (1000) to make 400 and 900. | |
| var romanToInt = function(string) { | |
| var reference = { | |
| '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
| //input string | |
| //output number | |
| // I can be placed before V (5) and X (10) to make 4 and 9. | |
| // X can be placed before L (50) and C (100) to make 40 and 90. | |
| // C can be placed before D (500) and M (1000) to make 400 and 900. | |
| var romanToInt = function(string) { | |
| var reference = { | |
| '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
| /** | |
| * Definition for binary tree | |
| * function TreeNode(val) { | |
| * this.val = val; | |
| * this.left = this.right = null; | |
| * } | |
| */ | |
| /** | |
| * @constructor |
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
| /** | |
| * Return true if this NestedInteger holds a single integer, rather than a nested list. | |
| * @return {boolean} | |
| * this.isInteger = function() { | |
| * ... | |
| * }; | |
| * Return the single integer that this NestedInteger holds, if it holds a single integer | |
| * Return null if this NestedInteger holds a nested list | |
| * @return {integer} | |
| * this.getInteger = function() { |
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
| /** | |
| * Return true if this NestedInteger holds a single integer, rather than a nested list. | |
| * this.isInteger = function() { | |
| * ... | |
| * }; | |
| * Return the single integer that this NestedInteger holds, if it holds a single integer | |
| * Return null if this NestedInteger holds a nested list | |
| * this.getInteger = function() { | |
| * ... | |
| * }; |
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
| /** | |
| * // This is the interface that allows for creating nested lists. | |
| * // You should not implement it, or speculate about its implementation | |
| * function NestedInteger() { | |
| * | |
| * Return true if this NestedInteger holds a single integer, rather than a nested list. | |
| * @return {boolean} | |
| * this.isInteger = function() { | |
| * ... | |
| * }; |
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
| //input = array, number | |
| //output = array | |
| //test case | |
| //[2, 7, 11, 15], 13 | |
| //[0, 2] | |
| function twoSum (array, number) { | |
| var solutionObject = {}; | |
| for (let i = 0; i < array.length; 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
| //input = integer | |
| //output = integer | |
| //test case | |
| // 123 | |
| // -> 321 | |
| function reverseInteger(integer) { | |
| var result = ''; | |
| var stringified = integer.toString(); |