摘要: Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].还是帕斯卡三角,只不过这里指定的是某一个特定的层,然后直接返回,这个就可以使用从后往前更新数组的方法,其... 阅读全文
posted @ 2015-10-28 22:34 eversliver 阅读(260) 评论(0) 推荐(0) 编辑
摘要: GivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]... 阅读全文
posted @ 2015-10-28 21:55 eversliver 阅读(388) 评论(0) 推荐(0) 编辑
摘要: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.首先是O(N)空间的方法,用递归: 1 /** 2 * Definit... 阅读全文
posted @ 2015-10-28 21:10 eversliver 阅读(259) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the... 阅读全文
posted @ 2015-10-28 19:56 eversliver 阅读(295) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, return thepostordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[3,2,1].No... 阅读全文
posted @ 2015-10-28 16:00 eversliver 阅读(249) 评论(0) 推荐(0) 编辑