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
/** | |
* Definition for singly-linked list. | |
* function ListNode(val) { | |
* this.val = val; | |
* this.next = null; | |
* } | |
*/ | |
var removeZeroSumSublists = function(head) { | |
const array = []; |
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} n | |
* @return {boolean} | |
*/ | |
var isHappy = function(n) { | |
const seen = new Set(); | |
const next = (n) => { | |
let sum = 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
/** | |
* Definition for singly-linked list. | |
* function ListNode(val) { | |
* this.val = val; | |
* this.next = null; | |
* } | |
*/ | |
/** | |
* @param {ListNode} head | |
* @return {ListNode} |
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[]} A | |
* @param {number} L | |
* @param {number} M | |
* @return {number} | |
*/ | |
/* | |
Brute Force: O((n-L)(n-M)) | |
Idea: For each possible window of size L, find |
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[]} queries | |
* @param {string} pattern | |
* @return {boolean[]} | |
*/ | |
// O(n) but massively overcomplicated. | |
var camelMatch = function(queries, pattern) { | |
const pCapSegments = capitalSegments(pattern); | |
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 {boolean} | |
*/ | |
// O(n) | |
// Idea: track the lowest and highest number so far. | |
// If you find a number higher than the highest so | |
// far, you've found a triplet sequence! | |
var increasingTriplet = function(nums) { |
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
/** | |
* Definition for singly-linked list. | |
* function ListNode(val) { | |
* this.val = val; | |
* this.next = null; | |
* } | |
*/ | |
/** | |
* @param {ListNode} head | |
* @return {ListNode} |
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
class Solution: | |
def rotateRight(self, head: ListNode, k: int) -> ListNode: | |
if not head: return None | |
# get the length of the list | |
length, current = 0, head | |
while current: | |
length+=1 | |
current = current.next | |
k%=length |
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
class MinStack: | |
def __init__(self): | |
""" | |
initialize your data structure here. | |
""" | |
self.mins = [] | |
self.stack = [] | |
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
""" | |
Idea: | |
- If the question asked us to find the longest line in one cardinal direction | |
(for example, south) from any point in the grid, we could just cache that | |
value for every cell. I.e., for every cell, starting from the bottom, draw | |
the longest line upwards that we can where at each cell the value = 1 + the | |
value at the cell below it. | |
- Instead, we're being asked to find the longest lin in ALL cardinal directions | |
so we can just repeat this process four times--once for each cardinal direction | |
- Now the kicker: they also want the longest symmetrical line, i.e., the minimum |