This file contains 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 {number} | |
*/ | |
var lengthOfLongestSubstring = function(s) { | |
let l = 0; | |
let r = 0; | |
let maxValue = 0; | |
const map = new Map(); |
This file contains 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(input) { | |
let globalMaxSum = input[0]; | |
let localMaxSun = input[0]; | |
for (let i = 1; i < input.length; i++) { | |
// flush the chain |
This file contains 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
// O(N*10) | |
const wordBreak = function(input) { | |
const map = new Map(); | |
// build a map based on the words length | |
for (word of input) { | |
const wordLength = word.length; | |
if (!map.has(wordLength)) { | |
map.set(wordLength, [word]); |
This file contains 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} target | |
* @return {number} | |
*/ | |
var searchInsert = function(input, target) { | |
let l = 0; | |
let r = input.length; | |
let index; | |
let m; |
This file contains 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 removeDuplicates = function(input) { | |
const maxMatches = 2; | |
let matched = 1; | |
let deleted = 0; |
This file contains 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[]} prices | |
* @return {number} | |
*/ | |
var maxProfit = function(prices) { | |
const pricesLength = prices.length; | |
let minBuyPrice = null; | |
let profit = 0; | |
This file contains 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} haystack | |
* @param {string} needle | |
* @return {number} | |
*/ | |
var strStr = function(haystack, needle) { | |
if (haystack === '' && needle === '' || needle === '') { | |
return 0; | |
} |
This file contains 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 removeDuplicates = function(nums) { | |
let result = 1; | |
for (let i = 1; i < nums.length; i++) { | |
// numbers are unique and well sorted | |
if (nums[i - 1] !== nums[i] && nums[i - 1] < nums[i]) { |
This file contains 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
const checkClasses = function(data) { | |
const classesMap = new Map(); | |
classesMap.set('upper', '3'); | |
classesMap.set('middle', '2'); | |
classesMap.set('lower', '1'); | |
let maxWeightLength = 0; | |
const result = []; | |
This file contains 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, next) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.next = (next===undefined ? null : next) | |
* } | |
*/ | |
/** | |
* @param {ListNode} list1 | |
* @param {ListNode} list2 |