摘要: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* m... 阅读全文
posted @ 2018-12-08 15:24 JTechRoad 阅读(103) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: vector res; vector findAllConcatenatedWordsInADict(vector& words) { unordered_set s(words.begin(), words.end()); for (auto & w : words) if... 阅读全文
posted @ 2018-12-08 15:20 JTechRoad 阅读(97) 评论(0) 推荐(0) 编辑
摘要: // O(nlogn) class Solution { public: int lengthOfLIS(vector& nums) { int n = nums.size(); if (n dp; dp.push_back(nums[0]); for (int i = 1; i & nums) { int n = num... 阅读全文
posted @ 2018-12-08 14:25 JTechRoad 阅读(84) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: vector> res; int m, n; vector> updateMatrix(vector>& matrix) { m = matrix.size(); if (m == 0) return res; n = matrix[0].size(); if (n==0) return ... 阅读全文
posted @ 2018-12-06 16:04 JTechRoad 阅读(169) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int maxDistToClosest(vector& seats) { int first = 0, last = seats.size() - 1; while (seats[first] == 0) first++; while (seats[last] == 0) las... 阅读全文
posted @ 2018-12-05 04:26 JTechRoad 阅读(80) 评论(0) 推荐(0) 编辑
摘要: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ cla... 阅读全文
posted @ 2018-12-04 15:56 JTechRoad 阅读(184) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: string convertToBase7(int num) { if (num == 0) return "0"; long n = abs(num); int flag = num > 0 ? 1 : -1; string res;... 阅读全文
posted @ 2018-12-04 01:13 JTechRoad 阅读(120) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int maxSubArray(vector& nums) { int res = nums[0], cur = nums[0]; for (int i = 1; i < nums.size(); i++) { cur = max(cur, 0) + nums[i]; ... 阅读全文
posted @ 2018-12-03 17:10 JTechRoad 阅读(85) 评论(0) 推荐(0) 编辑
摘要: // improvement: // 1) convert unordered_map to 26 bitmap (done) // 2) for each step in dfs, we don't have search the word from beginning in trie, // we can actually search from previous node. shou... 阅读全文
posted @ 2018-12-03 15:37 JTechRoad 阅读(143) 评论(0) 推荐(0) 编辑
摘要: class Solution { public: int m, n; bool exist(vector>& board, string word) { m = board.size(); if (m == 0) return false; n = board[0].size(); if (n == 0) return false; ... 阅读全文
posted @ 2018-12-03 14:16 JTechRoad 阅读(147) 评论(0) 推荐(0) 编辑