Skip to content

Instantly share code, notes, and snippets.

View haase1020's full-sized avatar
Coding with joy!

Mandi Haase haase1020

Coding with joy!
View GitHub Profile
@haase1020
haase1020 / sameTreeIterative. js
Created December 6, 2021 10:55
same tree leetcode #100
// Iterative solution: time complexity: O(n) | space complexity: O(n)
var isSameTree = function (p, q) {
const q1 = [];
q1.push(p);
const q2 = [];
q2.push(q);
while (q1.length && q2.length) {
const curr1 = q1.shift();
const curr2 = q2.shift();
@haase1020
haase1020 / sameTreeRecursive.js
Created December 6, 2021 10:57
same tree leetcode #100
// recursive solution: time complexity: O(n) | space complexity: O(h) where h is height of tree (recursion stack)
var isSameTree = function (p, q) {
if (!p && !q) {
return true;
}
if (!p || !q || p.val !== q.val) {
return false;
}
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
};
@haase1020
haase1020 / higher order functions
Created July 11, 2022 20:43
simple example of a higher order function
enum SIZE {
small = 'small',
medium = 'medium',
large = 'large'
}
function calculateAge(operation: Function, initialVal: number, factor: boolean | SIZE) {
const age = operation(initialVal, factor)
return age;
}