Binary Tree Level Order Traversal

摘要: /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: vector > levelOrder(TreeNode *root) { // Start typing your C/C++ solution below ... 阅读全文
posted @ 2013-09-11 15:38 邪灵天使 阅读(136) 评论(0) 推荐(0) 编辑

Maximum Depth of Binary Tree

摘要: /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {private: int height;public: int maxDepth(TreeNode *root) { // Start typing your C/C++ solution ... 阅读全文
posted @ 2013-09-11 15:27 邪灵天使 阅读(101) 评论(0) 推荐(0) 编辑

Balanced Binary Tree

摘要: /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {private: bool OK ;public: bool isBalanced(TreeNode *root) { // Start typing your C/C++ solution... 阅读全文
posted @ 2013-09-10 21:04 邪灵天使 阅读(115) 评论(0) 推荐(0) 编辑

Remove Element

摘要: class Solution {public: int removeElement(int A[], int n, int elem) { // Start typing your C/C++ solution below // DO NOT write int main() function for(int i = 0;i<n;) { if(A[i]==elem) { n--; swap(A[i],A[n]); ... 阅读全文
posted @ 2013-09-10 15:48 邪灵天使 阅读(88) 评论(0) 推荐(0) 编辑

Pascal's Triangle II

摘要: class Solution {public: vector getRow(int rowIndex) { // Start typing your C/C++ solution below // DO NOT write int main() function vector result; if(rowIndex temp; temp.push_back(1); result = temp; for(int i = 1;i<=rowIndex;i++) { ... 阅读全文
posted @ 2013-09-10 15:34 邪灵天使 阅读(105) 评论(0) 推荐(0) 编辑

Pascal's Triangle

摘要: class Solution {public: vector > generate(int numRows) { // Start typing your C/C++ solution below // DO NOT write int main() function vector > result; if(numRows temp; temp.push_back(1); result.push_back(temp); for(int i = 2;i<=numRows;i++) ... 阅读全文
posted @ 2013-09-10 15:29 邪灵天使 阅读(92) 评论(0) 推荐(0) 编辑

Path Sum II

摘要: /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {private: vector > sumpath; int refsum;public: vector > pathSum(TreeNode *root, int sum) { ... 阅读全文
posted @ 2013-09-10 15:14 邪灵天使 阅读(137) 评论(0) 推荐(0) 编辑

Path Sum

摘要: 每次用递归都怕栈溢出 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */10 class Solution {11 private: map sums;12 public:13 bool hasPathSum(TreeNode *r... 阅读全文
posted @ 2013-09-10 14:53 邪灵天使 阅读(115) 评论(0) 推荐(0) 编辑

plusOne

摘要: class Solution {public: vector plusOne(vector &digits) { // Start typing your C/C++ solution below // DO NOT write int main() function bool plus = true; vector::iterator iter = digits.end(); iter--; while(plus&&iter>=digits.begin()) { *i... 阅读全文
posted @ 2013-09-10 14:36 邪灵天使 阅读(117) 评论(0) 推荐(0) 编辑

Divide Two Integers

摘要: 如何实现不用除法来做除法,对比十进制除法可有二进制除法的算法,leetcode Divide Two Integers,当然也可在divide函数写入return dividend/divisor;即可A过class Solution {public: int divide(int dividend, int divisor) { // Start typing your C/C++ solution below // DO NOT write int main() function bool flag=true; if((divi... 阅读全文
posted @ 2013-09-08 20:39 邪灵天使 阅读(140) 评论(0) 推荐(0) 编辑