上一页 1 ··· 19 20 21 22 23 24 25 26 27 ··· 36 下一页
摘要: Two condition need to equal:1. A[mid] >= A[start]. Because mid = (start + end)/2; it shifts left2. A[end] >= target. Since did not check A[end] now. 1... 阅读全文
posted @ 2015-03-23 13:05 keepshuatishuati 阅读(111) 评论(0) 推荐(0) 编辑
摘要: Actually, we are searching the right end of the target so:1. start could be same as end2. A[mid] > target, shift to left3. A[mid] searchRange(int A[]... 阅读全文
posted @ 2015-03-23 12:56 keepshuatishuati 阅读(114) 评论(0) 推荐(0) 编辑
摘要: Binary search. Just need to convert index. 1 class Solution { 2 public: 3 bool searchMatrix(vector > &matrix, int target) { 4 if (matrix.s... 阅读全文
posted @ 2015-03-23 12:32 keepshuatishuati 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(i... 阅读全文
posted @ 2015-03-23 11:45 keepshuatishuati 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), ne... 阅读全文
posted @ 2015-03-23 11:44 keepshuatishuati 阅读(121) 评论(0) 推荐(0) 编辑
摘要: This is a math trick. 1 class Solution { 2 public: 3 void rotate(vector > &matrix) { 4 auto swap = [](int &a, int &b){int t = a; a = b; b... 阅读全文
posted @ 2015-03-23 10:48 keepshuatishuati 阅读(125) 评论(0) 推荐(0) 编辑
摘要: Note:1. K might be very very large. So remember to module it with n.2. two range reverse (0, k-1), (k, n-1). 1 class Solution { 2 public: 3 void r... 阅读全文
posted @ 2015-03-23 10:37 keepshuatishuati 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 int romanToInt(string s) { 4 int len = s.size(), result = 0; 5 for (int i = 0; i < len; i++) { 6 ... 阅读全文
posted @ 2015-03-23 10:28 keepshuatishuati 阅读(105) 评论(0) 推荐(0) 编辑
摘要: Reverse in place:1. reverse the whole sentence.2. reverse every word.We cant do it for I, because there are extra spaces in sentence. 1 class Solution... 阅读全文
posted @ 2015-03-23 10:20 keepshuatishuati 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 void reverseWords(string &s) { 4 string result; 5 int len = s.size(); 6 for (int i = len-1... 阅读全文
posted @ 2015-03-23 10:13 keepshuatishuati 阅读(90) 评论(0) 推荐(0) 编辑
上一页 1 ··· 19 20 21 22 23 24 25 26 27 ··· 36 下一页