Skip to content

Instantly share code, notes, and snippets.

View MichaelDimitras's full-sized avatar

Michael Dimitras MichaelDimitras

  • San Francisco Bay Area
View GitHub Profile
@MichaelDimitras
MichaelDimitras / kthSmallestChildBST.js
Created April 30, 2018 16:53
A program that finds the Kth smallest element in a BST
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @param {number} k
["accelerator", "accordion", "account", "accountant", "acknowledgment", "acoustic", "acrylic", "act", "action", "active", "activity", "actor", "actress", "adapter", "addition", "address", "adjustment", "adult", "advantage", "advertisement", "advice", "afghanistan", "africa", "aftermath", "afternoon", "aftershave", "afterthought", "age", "agenda", "agreement", "air", "airbus", "airmail", "airplane", "airport", "airship", "alarm", "albatross", "alcohol", "algebra", "algeria", "alibi", "alley", "alligator", "alloy", "almanac", "alphabet", "alto", "aluminium", "aluminum", "ambulance", "america", "amount", "amusement", "anatomy", "anethesiologist", "anger", "angle", "angora", "animal", "anime", "ankle", "answer", "ant", "antarctica", "anteater", "antelope", "anthony", "anthropology", "apartment", "apology", "apparatus", "apparel", "appeal", "appendix", "apple", "appliance", "approval", "april", "aquarius", "arch", "archaeology", "archeology", "archer", "architecture", "area", "argentina", "argument", "aries", "ari
const { Client } = require('pg');
var config = {
user: 'michaeldimitras', // env var: PGUSER
database: 'reviews', // env var: PGDATABASE
password: null, // env var: PGPASSWORD
port: 5432, // env var: PGPORT
}
const client = new Client(config);
@MichaelDimitras
MichaelDimitras / path-to-target-sum.js
Created April 12, 2018 16:51
Find if a BST contains a path from root to leaf that adds to a specific target
class bst {
constructor(val) {
this.value = val;
this.left = null;
this.right = null;
}
insert(val) {
if (val < this.value) {
if(this.left === null) this.left = new bst(val);