Skip to content

Instantly share code, notes, and snippets.

View ykdojo's full-sized avatar

YK ykdojo

View GitHub Profile
import time
Ts = []
Ns = []
for multiple in range(1, 11):
N = 10 * multiple
Ns.append(N)
STR_LENGTH = 3000
root = Node('a'*STR_LENGTH)
current = root
N_trials = 10
// this function allows us to stop our code for |ms| milliseconds.
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// I've put our main code into this function.
async function addPeople() {
ul = $('ul.mn-pymk-list__cards')[0];
firstLi = ul.querySelector('li');
count = 0; // this is the count of how many people you've added
class Solution:
# NOTE: extra space: O(m), time: O(n + m)
def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
"""
Do not return anything, modify nums1 in-place instead.
"""
nums1_copy = [None] * m
for i in range(m):
nums1_copy[i] = nums1[i]
/**
* @param {number[]} nums1
* @param {number} m
* @param {number[]} nums2
* @param {number} n
* @return {void} Do not return anything, modify nums1 in-place instead.
*/
// NOTE: extra space: O(m), time: O(n + m)
var merge = function(nums1, m, nums2, n) {
nums1Copy = Array(m);
var helper = function(current, last, target) {
if (current == target) {
return 0;
} else if (current > target) {
return Infinity;
}
let option1 = last != current ? helper(current, current, target) + 1 : Infinity;
let option2 = last != 0 ? helper(current + last, last, target) + 1 : Infinity;
if (option1 < option2) {
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {boolean}
/**
* @param {number[]} nums
* @return {number}
*/
var rob = function(nums) {
return helper(nums, 0);
};
var helper = function(nums, current) {
if (current > nums.length) {
/**
* @param {number[]} nums
* @return {number}
*/
var rob = function(nums) {
let memo = Array(nums.length);
return helper(nums, 0, memo);
};
var helper = function(nums, current, memo) {
/**
* @param {number[]} A
* @return {boolean}
*/
var validMountainArray = function(A) {
if (A.length < 3) {
return false;
}
let current = A[0];
let i = 1;
/**
* @param {number[]} nums
* @return {boolean}
*/
var increasingTriplet = function(nums) {
let currentMin = nums[0];
let minWithSmaller = Infinity;
for (let i = 1; i < nums.length; i++) {
if (nums[i] > minWithSmaller) {