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
/* | |
Notes | |
- subsequence doesn't necessarily mean that they are adjacent in the array | |
- a single number in the array and the array itself count as a subsequence | |
- run through main array | |
- set counter to 0 | |
- check if number equals number in second array | |
- if yes: |
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
var asteroidCollision = function(asteroids) { | |
let stack = []; | |
for (let i = 0; i < asteroids.length; i++) { | |
let add = true; | |
if (asteroids[i] < 0 && stack[stack.length-1] > 0) { | |
while (stack.length !== 0 && stack[stack.length-1] > 0) { | |
if (Math.abs(asteroids[i]) > Math.abs(stack[stack.length-1])) { | |
stack.pop(); |
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 longestPalindrome = function (s) { | |
const counts = {}; | |
let sum = 0; | |
let oddPresent = false; | |
for (let i = 0; i < s.length; 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
class SinglyLinkedList { | |
constructor() { | |
this.head = null; | |
this.tail = null; | |
this.length = 0; | |
} | |
// check out this gist: https://gist.github.com/joannaylin/d3dfc926ba73833138e4571c8a0f9a15 | |
// for the full implementation of the singly linked list. |
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
class Node { | |
constructor(val) { | |
this.val = val; | |
this.next = null; | |
} | |
} | |
class SinglyLinkedList { | |
constructor() { | |
this.head = null; |