create, read, update and delete
This file contains 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
function a () { | |
var value = 1; | |
return{ | |
get: function(){ | |
return value | |
}, | |
set: function(n){ | |
value = n | |
return value |
This file contains 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
var assert = require('assert') | |
/** | |
* @param {character[][]} grid | |
* @return {number} | |
*/ | |
var numIslands = function(grid) { | |
var count = 0 | |
var max = -Infinity | |
var min = Infinity |
This file contains 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
var stock1 = function(prices) { | |
if(prices.length <= 1) return 0 | |
var max = 0 | |
var min = Infinity | |
for(var i = 0; i < prices.length; i++){ | |
min = Math.min(min, prices[i]) | |
var profit = prices[i] - min | |
max = Math.max(max, profit) | |
} | |
return max |
This file contains 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
//close hashing | |
//an array | |
function Hash(len, capacity) { | |
this.len = len | |
this.capacity = capacity | |
this.arr = new Array(len) | |
this.size = 0 | |
} |
This file contains 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
function Node(key, val) { | |
this.key = key | |
this.val = val | |
this.next = undefined | |
} | |
function Hash(len, capacity) { | |
this.len = len | |
this.arr = new Array(len) | |
this.capacity = capacity |
This file contains 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
function generateIndex(key){ | |
var sum = 0 | |
for(var i = 0; i < key.length; i++){ | |
sum = sum * 33 + key.charCodeAt(i) | |
sum = sum % this.len | |
} | |
return sum | |
} |
This file contains 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
var assert = require('assert') | |
function maxSumIncrease(arr){ | |
if(arr.length === 0) return 0 | |
var max = arr[0] | |
var sum = arr[0] | |
for(var i = 1; i < arr.length; i++){ | |
if(arr[i] === arr[i - 1] + 1){ | |
sum += arr[i] |
This file contains 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
var assert = require('assert') | |
var maze = [ | |
[1,0,1,1,0], | |
[1,0,1,0,0], | |
[1,0,0,0,0], | |
[1,0,0,0,0] | |
] |
This file contains 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
//设计一个类Time Traveling Hashtable,有以下方法: | |
// void put(double t, String k, String v) 在某一时刻t以k为键v为值加入hashtable | |
// String get(double t, String k) 对于k,获得某一时刻t之前(或相等)离t时间上最近的value | |
// void remove(double t, String k) 对于k,删除某一时刻t之前(或相等)离t时间上最近的value | |
// 比如在如下操作之后 | |
// ht.put(1, "A", "X"); | |
// ht.put((2, "A", "Y"); | |
// ht.put(0, "A", "M"); |