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
let J = "aA", S = "aAAbbbb" | |
let X = "z", Y = "ZZ"; | |
const numJewelsInStones = (J, S) => { | |
return [...S].reduce((sum, s) => sum += J.includes(s), 0); | |
}; | |
console.log( numJewelsInStones(J, S) ); | |
console.log( numJewelsInStones(X, Y) ); |
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
def hammingDistance(self, x, y): | |
xor = bin(x^y) | |
return xor.count("1") |
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
def shortestToChar(self, S: 'str', C: 'str') -> 'List[int]': | |
# store index of all chars c | |
ind = [] | |
for i,c in enumerate(S): | |
if (c == C): | |
ind.append(i) | |
# Find shortest distance | |
# from current i to indexed c | |
arr = [] |
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
def twoSum(self, nums: 'List[int]', target: 'int') -> 'List[int]': | |
index = {} | |
for i,num in enumerate(nums): | |
# build dictionary | |
if index.get(num) == None: | |
index[num] = i; | |
# if (target - num) is in dict | |
if index.get(target - num) != None: | |
if i != index.get(target-num): # cannot use same element |
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
def sortArrayByParity(self, A): | |
A.sort(key=lambda x: x%2) | |
return A |
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
netsh int ipv4 set dynamicport tcp start=1025 num=64510 | |
netsh int ipv4 show dynamicport tcp | |
New-ItemProperty ` | |
-Path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" ` | |
-Name "TcpTimedWaitDelay" ` | |
-Value "30" ` | |
-PropertyType "DWord" |
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
def sortedSquares(self, A: List[int]) -> List[int]: | |
B = [i**2 for i in A] | |
B.sort() | |
return B |
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
def flipAndInvertImage(self, A: List[List[int]]) -> List[List[int]]: | |
return [[int(not i) for i in row[::-1]] for row in A] |
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
{ | |
"message": "This certifies that bcowell completed the mazebot race in 123.812 seconds.", | |
"elapsed": 123.812, | |
"completed": "2019-07-15T03:47:00.566Z" | |
} |
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
# Given a string sentence, return the sentence with the words in the reverse order | |
# "I like apples" => "apples like I" | |
def reverseSentence(sentence): | |
words = sentence.split(" ") | |
return " ".join(words[::-1]) | |
# If input is an array of characters instead of a string | |
# ['I', ' ', 'l' , 'i', 'k', e', ' ', 'a', 'p', 'p', 'l', 'e', 's'] | |
# => ['a', 'p', 'p', 'l', 'e', 's', ' ', 'l', 'i', 'k', 'e', ' ', 'I'] | |
def reverseSentenceArray(arr): |
OlderNewer