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
/\(?\d{3}\)?\s*-?\s*\d{3}\s*-?\s*\d{4}/.test() | |
false | |
const testValue = 'sdfsdf425 - 319 - 5483' | |
undefined | |
/\(?\d{3}\)?\s*-?\s*\d{3}\s*-?\s*\d{4}/.test(testValue) | |
true | |
testValue.match(/\(?\d{3}\)?\s*-?\s*\d{3}\s*-?\s*\d{4}/) | |
['425 - 319 - 5483', index: 6, input: 'sdfsdf425 - 319 - 5483', groups: undefined]0: "425 - 319 - 5483"groups: undefinedindex: 6input: "sdfsdf425 - 319 - 5483"length: 1[[Prototype]]: Array(0) | |
testValue.match(/\(?\d{3}\)?\s*-?\s*\d{3}\s*-?\s*\d{4}/)[0].match(/\d/) | |
['4', index: 0, input: '425 - 319 - 5483', groups: undefined]0: "4"groups: undefinedindex: 0input: "425 - 319 - 5483"length: 1[[Prototype]]: Array(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
# 0 IS too far from ` ;) | |
set -g base-index 1 | |
# Automatically set window title | |
set-window-option -g automatic-rename on | |
set-option -g set-titles on | |
# set -g set-titles-string '#S - #W' | |
set -g set-titles-string '~' | |
set -g status-keys vi |
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
let toggleLog = false; | |
toggleLog = true; | |
let log = false; | |
// log = true; | |
const parents = {}; | |
let numKeys = 0; | |
class UnionSet { | |
// End result: At each cell, check adjacent, if it's visited, set parent to it's parent |
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
let distanceMemo = new Map(); | |
var kClosest = function(points, K) { | |
// Choose pivot | |
// pseudo sort all items around pivot | |
// Get new partition position | |
// If K is larger, do again with a pivot in smaller section | |
// vice versa | |
let left = 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 wordBreak = function(s, wordDict) { | |
let dict = new Set(wordDict); | |
let isValid = Array(s.length + 1).fill(false); | |
isValid[0] = true; | |
for (let i = 1; i <= s.length; i++) { | |
for (let j = 0; j < i; j++) { | |
if (isValid[j] && dict.has(s.substring(j, i))) { | |
isValid[i] = true; | |
break; |
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 productExceptSelfTwoArray = function(nums) { | |
const prodLeft = []; | |
const prodRight = []; | |
prodLeft[0] = 1; | |
prodRight[nums.length - 1] = 1; | |
const ans = []; |
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 findAllConcatenatedWordsInADict = function(words) { | |
words.sort((a, b) => a.length - b.length); | |
let wordSet = new Set(); | |
words.forEach(word => { | |
// Use Trie | |
if (word) wordSet.add(word); | |
}); | |
// DFS |
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 topKFrequent = function(words, k, frequency = {}) { | |
words.forEach(word => frequency[word] = frequency[word] + 1 || 1); | |
return Object.keys(frequency).sort((left, right) => { | |
const freqDiff = frequency[right] - frequency[left]; | |
return freqDiff === 0 ? left.localeCompare(right) : freqDiff; | |
}).slice(0, k); | |
}; |
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[]} sentences | |
* @param {number[]} times | |
*/ | |
var AutocompleteSystem = function(sentences, times) { | |
this.trie = { letters: {} }; | |
this.sentences = {}; | |
this.searchInput = ''; | |
sentences.forEach((sentence, sentenceIdx) => { |
NewerOlder