Skip to content

Instantly share code, notes, and snippets.

View remi-bruguier's full-sized avatar
🎯

Rémi BRUGUIER remi-bruguier

🎯
View GitHub Profile
@remi-bruguier
remi-bruguier / uniqueNumber.ts
Created May 17, 2020 15:46
Given a list of numbers, where every number shows up twice except for one number, find that one number.
const uniqueNumber = (arr:number[]):number => arr.reduce((x,y) => x^y);
@remi-bruguier
remi-bruguier / twoSum.ts
Created May 16, 2020 12:37
Return whether or not there are two numbers in the list that add up to k.
const twoSum = (numbers:number[], k: number): Boolean => {
const rec:Record<number,number>= {};
for(const n of numbers){
rec[n] = n;
if(rec.hasOwnProperty(k-n)) return true;
}
return false;
@remi-bruguier
remi-bruguier / validParentheses.js
Last active May 12, 2020 19:46
validParentheses
/**
* Valid Parentheses
* @param {string} s
* @return {boolean}
*/
const validParentheses = (s) => {
if (s === null || !s.length) return true;
const chars = s.split('');
const stack = [];