Skip to content

Instantly share code, notes, and snippets.

View bcowell's full-sized avatar

Brayden Cowell bcowell

View GitHub Profile
@bcowell
bcowell / jewels-and-stones.js
Last active February 12, 2019 20:53
28/01/2019 - 771. Jewels and Stones [Easy] bcowell
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) );
@bcowell
bcowell / hamming-distance.py
Last active February 12, 2019 20:53
hamming-distance
def hammingDistance(self, x, y):
xor = bin(x^y)
return xor.count("1")
@bcowell
bcowell / shortest-to-char.py
Last active February 12, 2019 20:54
shortest-to-char
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 = []
@bcowell
bcowell / two-sum.py
Created February 13, 2019 16:38
two-sum
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
@bcowell
bcowell / sort-array-by-parity.py
Last active February 20, 2019 15:07
sort-array-by-parity
def sortArrayByParity(self, A):
A.sort(key=lambda x: x%2)
return A
@bcowell
bcowell / tcp-timed-wait-delay.ps1
Last active February 21, 2019 21:36
Powershell command - Edit TcpTimedWaitDelay
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"
@bcowell
bcowell / squares-of-sorted-array.py
Created March 13, 2019 13:40
Squares of a Sorted Array
def sortedSquares(self, A: List[int]) -> List[int]:
B = [i**2 for i in A]
B.sort()
return B
@bcowell
bcowell / flipping-an-image.py
Last active March 29, 2019 18:11
Flipping an image
def flipAndInvertImage(self, A: List[List[int]]) -> List[List[int]]:
return [[int(not i) for i in row[::-1]] for row in A]
@bcowell
bcowell / mazebot-cert.json
Last active July 15, 2019 03:50
Noops Mazebot race cert solved using A*
{
"message": "This certifies that bcowell completed the mazebot race in 123.812 seconds.",
"elapsed": 123.812,
"completed": "2019-07-15T03:47:00.566Z"
}
@bcowell
bcowell / reverseSentence.py
Created October 23, 2019 16:09
Given a string sentence, return the sentence with the words in the reverse order
# 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):