Skip to content

Instantly share code, notes, and snippets.

View LeeYeeze's full-sized avatar

Yize Li LeeYeeze

View GitHub Profile
function partition(arr, left, right, pivot) {
var temp = arr[pivot];
arr[pivot] = arr[right];
arr[right] = temp;
var track = left;
for (var i = left; i < right; i++) {
if (arr[i]<arr[right]) {
var t = arr[i];
arr[i] = arr[track];
arr[track] = t;
function AVLTreeNode(val,left,right) {
this.val = val;
this.left = left || null;
this.right = right || null;
this.height = 0;
}
function AVLTree(comparator) {
this.comparator = comparator;
this.root = null;
'use strict';
;(function(global) {
function SegmentTreeNode(left, right, reocrd) {
this.left = left;
this.right = right;
this.leftChild = null;
this.rightChild = null;
this.cover = false;
this.record = reocrd;
}
@LeeYeeze
LeeYeeze / weighted_interval_scheduling_with_constrain_on_number_of_intervals.js
Last active August 29, 2015 14:16
Weighted interval scheduling with upper bound on number of intervals JavaScript
function fillArray(arr, size, val) {
for (var i = 0; i < size; i++) {
arr[i] = val;
}
}
function binarySearch (array, target, start, end) {
var l = start || 0;
var r = end || array.length - 1;
while (l<=r) {
@LeeYeeze
LeeYeeze / weightedTaskScheduling.js
Last active August 29, 2015 14:16
weighted task scheduling
function binarySearch (array, target, start, end) {
var l = start || 0;
var r = end || array.length - 1;
while (l<=r) {
var mid = Math.floor((l+r)/2);
if (array[mid]==target) {
return mid;
} else if (array[mid]>target) {
r = mid - 1;
} else {
@LeeYeeze
LeeYeeze / Trie for Suffix.js
Last active August 29, 2015 14:16
Trie for suffix, construction in O(n) JavaScript
function SuffixTrieNode() {
this.children = {};
this.link = null;
}
SuffixTrieNode.prototype.addLink = function(c, v) {
this.children[c] = v;
};
function SuffixTrie(s) {