代码改变世界

leetcode - Binary Tree Level Order Traversal II

2013-03-04 09:32 by 张汉生, 228 阅读, 0 推荐, 收藏, 编辑
摘要:题目描述:点击此处 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 public:12 vector<vector<int> > levelOrderBottom(... 阅读全文

leetcode - Binary Tree Level Order Traversal

2013-03-04 09:23 by 张汉生, 144 阅读, 0 推荐, 收藏, 编辑
摘要:题目描述:点击此处 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 public:12 vector<vector<int> > levelOrder(TreeNode *root) {... 阅读全文

HttpClient4.2.1忽略https中的SSL证书失效

2013-03-03 22:58 by 张汉生, 4037 阅读, 0 推荐, 收藏, 编辑
摘要:网上大多数解决方法针对的是以前的版本,其中有几个用到的方法已经过时,deprecation。备份。解决的方法是创建一个能够接受所有域名的证书,然后注册到client里面去。 1 public class TestClient extends DefaultHttpClient{ 2 TestClient() throws Exception{ 3 super(); 4 SSLContext ctx = SSLContext.getInstance("TLS"); 5 X509TrustManager tm = new X509TrustManager() { 6... 阅读全文

leetcode - Binary Tree Inorder Traversal

2013-03-03 22:43 by 张汉生, 160 阅读, 0 推荐, 收藏, 编辑
摘要: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 public:12 vector inorderTraversal(TreeNode *root) {13 // Not... 阅读全文

leetcode - Best Time to Buy and Sell Stock III

2013-03-03 21:50 by 张汉生, 137 阅读, 0 推荐, 收藏, 编辑
摘要:题目描述:点击此处 1 class Solution { 2 public: 3 int maxProfit(vector<int> &prices) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 int profit = 0; 7 vector<int>::iterator ii; 8 int size = prices.size(); 9 if (size ==0 )10 ... 阅读全文

leetcode - Best Time to Buy and Sell Stock Ⅱ

2013-03-03 20:22 by 张汉生, 143 阅读, 0 推荐, 收藏, 编辑
摘要:题目描述:点击此处 1 class Solution { 2 public: 3 int maxProfit(vector<int> &prices) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 int lastBuy = 0, lastView = 0, profit =0; 7 vector<int>::iterator ii; 8 if (!prices.empty()){ 9 ... 阅读全文

leetcode - Best Time to Buy and Sell Stock

2013-03-03 20:18 by 张汉生, 140 阅读, 0 推荐, 收藏, 编辑
摘要:题目描述:点击此处 1 class Solution { 2 public: 3 int maxProfit(vector<int> &prices) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 int min = 1000000000; 7 vector<int>::iterator ii; 8 int profit = 0; 9 for (ii=prices.b... 阅读全文

leetcode - Balanced Binary Tree

2013-03-03 20:15 by 张汉生, 167 阅读, 0 推荐, 收藏, 编辑
摘要:题目描述:点击此处 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 11 class Solution {12 public:13 int getDepth(TreeNode * node, bool & rlt){14 ... 阅读全文

leetcode - Anagrams

2013-03-03 20:14 by 张汉生, 151 阅读, 0 推荐, 收藏, 编辑
摘要:题目描述:点击此处class Solution {public: vector<string> anagrams(vector<string> &strs) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<string> strs_copy = strs; vector<string> rlt; vector<string> real_rlt; vector<str... 阅读全文

leetcode - Add Two Numbers

2013-03-03 19:56 by 张汉生, 145 阅读, 0 推荐, 收藏, 编辑
摘要:题目描述:点击此处 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution {10 public:11 ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) {12 // Start typing ... 阅读全文