File tree Expand file tree Collapse file tree 6 files changed +39
-0
lines changed
Expand file tree Collapse file tree 6 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 1+ 最长长度为左边子树深度+右边子树深度最大的值
Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 1+ 二维数组按照层次顺序,4个一组来替换位置
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {string } s
3+ * @param {number } numRows
4+ * @return {string }
5+ */
6+ var convert = function ( s , numRows ) {
7+ const arr = [ ]
8+ } ;
You can’t perform that action at this time.
0 commit comments