Skip to content

Commit b89c4ef

Browse files
committed
init commit
0 parents  commit b89c4ef

File tree

7 files changed

+101
-0
lines changed

7 files changed

+101
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.swp

avl_tree.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Avl 二叉平衡树
3+
*/
4+

house_rob.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Leet Code
2+
# 一个贼,去别人家偷东西,不能偷连续的两家,否则会报警,
3+
# 每家能偷的金额已经知道了,选择偷哪几家能够最大化收益?
4+
5+
def rob(nums):
6+
now = 0
7+
last = 0
8+
9+
for n in nums:
10+
temp = now
11+
now = max(now, last + n)
12+
last = temp
13+
14+
return now
15+
16+
17+
if __name__ == '__main__':
18+
houses = [1, 34, 56, 1, 26, 99, 100, 200, 1, 2, 98]
19+
print(rob(houses))

red_black_tree.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/**
2+
* 红黑树
3+
*/

reverseString.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Reverse an array which contains much more chars.
3+
*/
4+
5+
const a = [":","W","\"","7"," ",".","s"," ","6","S","v","X",";","P","!","i"," ","1","`","0",".","\"","8","f",".","Y","W","7"," ","5","u","f","m","Q","V","E","X","!","E","D","e","Z","`","p","0","!","l","8","9","'","!","'","x","V","o","?","N","P","S","j","'","Q","?","s","?","'","2","T","0","R","N","p","n","v","7","u","u","?","v","?","!",";","a","!"," ","v"," ","\"","S","3","7","2","Y","`","B","j","5","l","3","2","H",";","f","u",":","`","8","X","!","Q","B","M","0","'","`","7","'","\""," ","\"",",","5",".","0","Q"," "," "," "," ","Q","0",".","5",",","\""," ","\"","3","7","`","3","0","M","B","Q","!","X","8","`",":","u","f",";","H","2","3","l","5","j","B","`","Y","2","7","3","S","\""," ","v"," ","!","a",";","!","?","v","?","u","u","7","v","n","p","N","R","0","T","2","'","?","s","?","Q","'","j","S","P","N","?","o","V","x","'","!","'","9","8","l","!","0","p","`","Z","e","D","E","!","X","E","V","Q","m","f","u","5"," ","7","W","Y",".","f","8","\"",".","0","`","1"," ","i","!","P",";","X","v","S","6"," ","s","."," ","7","\"","W",":"]
6+
7+
const reverseString = function(s) {
8+
const size = s.length
9+
const lastIndex = size - 1;
10+
11+
const halfSize = size / 2;
12+
const absHalfSize = parseInt(halfSize)
13+
14+
const middleIndex = halfSize === absHalfSize ? absHalfSize - 1 : absHalfSize
15+
16+
17+
for (let i=0; i <= middleIndex; i++) {
18+
var j = s[i]
19+
20+
s[i] = s[lastIndex - i]
21+
s[lastIndex - i] = j
22+
23+
}
24+
};
25+
26+
reverseString(a)

reverseStringArray.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Reverse an array which contains much more chars.
3+
*/
4+
5+
const a = [":","W","\"","7"," ",".","s"," ","6","S","v","X",";","P","!","i"," ","1","`","0",".","\"","8","f",".","Y","W","7"," ","5","u","f","m","Q","V","E","X","!","E","D","e","Z","`","p","0","!","l","8","9","'","!","'","x","V","o","?","N","P","S","j","'","Q","?","s","?","'","2","T","0","R","N","p","n","v","7","u","u","?","v","?","!",";","a","!"," ","v"," ","\"","S","3","7","2","Y","`","B","j","5","l","3","2","H",";","f","u",":","`","8","X","!","Q","B","M","0","'","`","7","'","\""," ","\"",",","5",".","0","Q"," "," "," "," ","Q","0",".","5",",","\""," ","\"","3","7","`","3","0","M","B","Q","!","X","8","`",":","u","f",";","H","2","3","l","5","j","B","`","Y","2","7","3","S","\""," ","v"," ","!","a",";","!","?","v","?","u","u","7","v","n","p","N","R","0","T","2","'","?","s","?","Q","'","j","S","P","N","?","o","V","x","'","!","'","9","8","l","!","0","p","`","Z","e","D","E","!","X","E","V","Q","m","f","u","5"," ","7","W","Y",".","f","8","\"",".","0","`","1"," ","i","!","P",";","X","v","S","6"," ","s","."," ","7","\"","W",":"]
6+
7+
const reverseString = function(s) {
8+
const size = s.length
9+
const lastIndex = size - 1;
10+
11+
const halfSize = size / 2;
12+
const absHalfSize = parseInt(halfSize)
13+
14+
const middleIndex = halfSize === absHalfSize ? absHalfSize - 1 : absHalfSize
15+
16+
17+
for (let i=0; i <= middleIndex; i++) {
18+
var j = s[i]
19+
20+
s[i] = s[lastIndex - i]
21+
s[lastIndex - i] = j
22+
23+
}
24+
};
25+
26+
reverseString(a)

string-reverse.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 反转字符串
3+
*
4+
* 'chenyuan' ---> 'nauynehc'
5+
*/
6+
7+
const reverseString = str => {
8+
const strLength = str.length
9+
let result = ''
10+
11+
for (let i = strLength - 1; i > -1; i--) {
12+
result += str[i]
13+
}
14+
15+
return result
16+
}
17+
18+
a = 'chenyuan, hello0, world'
19+
20+
console.log(a)
21+
22+
console.log(reverseString(a))

0 commit comments

Comments
 (0)