Skip to content

Commit 49e448c

Browse files
author
谭佳胜
committed
submit code
1 parent d39e6e6 commit 49e448c

File tree

6 files changed

+39
-0
lines changed

6 files changed

+39
-0
lines changed

Diameter of Binary Tree/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const depth = function(node, result) {
2+
if (!node) return 0;
3+
4+
const leftDepth = depth(node.left, result);
5+
const rightDepth = depth(node.right, result);
6+
7+
result.val = Math.max(leftDepth + rightDepth + 1, result.val);
8+
9+
return Math.max(leftDepth, rightDepth) + 1;
10+
}
11+
const diameterOfBinaryTree = function(root) {
12+
const result = { val: 1 };
13+
depth(root, result);
14+
return result.val - 1;
15+
};

Diameter of Binary Tree/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
最长长度为左边子树深度+右边子树深度最大的值

Rotate Image/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const rotate = function(matrix) {
2+
const n = matrix.length;
3+
const layer = parseInt(n / 2);
4+
5+
for (let i = 0; i < layer; i++) {
6+
for (let j = 0; j < n - 2 * i - 1; j++) {
7+
let temp = matrix[i + j][i];
8+
matrix[i + j][i] = matrix[n - i - 1][i + j];
9+
matrix[n - i - 1][i + j] = matrix[n - i - j - 1][n - i - 1];
10+
matrix[n - i - j - 1][n - i - 1] = matrix[i][n - i - j - 1];
11+
matrix[i][n - i - j - 1] = temp;
12+
}
13+
}
14+
};

Rotate Image/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
二维数组按照层次顺序,4个一组来替换位置

ZigZag Conversion/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @param {string} s
3+
* @param {number} numRows
4+
* @return {string}
5+
*/
6+
var convert = function(s, numRows) {
7+
const arr = []
8+
};

ZigZag Conversion/readme.md

Whitespace-only changes.

0 commit comments

Comments
 (0)