随笔分类 -  Leetcode

摘要:/** * 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-06-01 13:50 JTechRoad 阅读(95) 评论(0) 推荐(0)
摘要:class Solution { public: int numDecodings(string s) { int n = s.length(); if (n == 0) return 0; vector dp(n+1, 0); dp[0] = 1; for (int i = 0; i 0) { ... 阅读全文
posted @ 2018-06-01 13:33 JTechRoad 阅读(163) 评论(0) 推荐(0)
摘要:// TODO: need improve!!! class Log { public: int id; bool start; int timestamp; int comp; // compasation Log() { id = 0; timestamp = 0; comp = 0; ... 阅读全文
posted @ 2018-05-30 15:11 JTechRoad 阅读(167) 评论(0) 推荐(0)
摘要:class Solution { public: int leastInterval(vector& tasks, int n) { int freq[26] = {0}; for (auto t : tasks) { freq[t-'A']++; } int max_freq = 0, max_fr... 阅读全文
posted @ 2018-05-30 14:24 JTechRoad 阅读(96) 评论(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-05-30 13:55 JTechRoad 阅读(92) 评论(0) 推荐(0)
摘要:class Solution { public: int leastBricks(vector>& wall) { unordered_map m; for (int i = 0; i < wall.size(); i++) for (int j = 0, t = 0; j < wall[i].size() - 1; j++) { ... 阅读全文
posted @ 2018-05-30 13:34 JTechRoad 阅读(81) 评论(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-05-29 23:33 JTechRoad 阅读(76) 评论(0) 推荐(0)
摘要:class Solution { public: long max_id = 0; unordered_map id_long; // Encodes a URL to a shortened URL. string encode(string longUrl) { id_long[max_id++] = longUrl; ... 阅读全文
posted @ 2018-05-29 23:25 JTechRoad 阅读(108) 评论(0) 推荐(0)
摘要:class Solution { public: bool checkSubarraySum(vector& nums, int k) { unordered_map m; // 从头元素开始的sum,取模为key的index。 m[0] = -1; int _sum = 0; for (int i = 0; i < n... 阅读全文
posted @ 2018-05-29 23:13 JTechRoad 阅读(90) 评论(0) 推荐(0)
摘要:class Solution { public: unordered_map dp; int findTargetSumWays(vector& nums, int S) { return helper(nums, S, 0); } int helper(vector& nums, int S, int start) { strin... 阅读全文
posted @ 2018-05-29 14:56 JTechRoad 阅读(77) 评论(0) 推荐(0)
摘要:class Solution { public: int totalHammingDistance(vector& nums) { int res = 0; for (int i = 0; i < 32; i++) { int ones = 0; for (int n : nums) { ... 阅读全文
posted @ 2018-05-29 13:35 JTechRoad 阅读(80) 评论(0) 推荐(0)
摘要:class Solution { public: int hammingDistance(int x, int y) { int r = x ^ y; return bitCount(r); } int bitCount(int x) { int res = 0; while (x) { ... 阅读全文
posted @ 2018-05-28 22:44 JTechRoad 阅读(88) 评论(0) 推荐(0)
摘要:class Solution { public: int splitArray(vector& nums, int m) { int _max = -1, _sum = 0; for (auto n : nums) { if (n > _max) _max = n; _sum += n; ... 阅读全文
posted @ 2018-05-27 15:28 JTechRoad 阅读(75) 评论(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-05-26 15:01 JTechRoad 阅读(84) 评论(0) 推荐(0)
摘要:class RandomizedSet { public: vector data; unordered_map m; // /** Initialize your data structure here. */ RandomizedSet() { } /** Inserts a value to the set.... 阅读全文
posted @ 2018-05-26 14:31 JTechRoad 阅读(110) 评论(0) 推荐(0)
摘要:递归 TLE DP 阅读全文
posted @ 2018-05-25 15:24 JTechRoad 阅读(92) 评论(0) 推荐(0)
摘要:/** * // This is the interface that allows for creating nested lists. * // You should not implement it, or speculate about its implementation * class NestedInteger { * public: * // Return ... 阅读全文
posted @ 2018-05-25 14:35 JTechRoad 阅读(78) 评论(0) 推荐(0)
摘要:class Solution { public: bool increasingTriplet(vector& nums) { int i = INT_MAX, j = INT_MAX; for (int n : nums) { if (n <= i) { i = n; } ... 阅读全文
posted @ 2018-05-25 13:59 JTechRoad 阅读(75) 评论(0) 推荐(0)
摘要:class Solution { public: unordered_set res; // DFS may produce dup result, use set to filter. vector removeInvalidParentheses(string s) { // Calculate rmL and rmR for the numbers o... 阅读全文
posted @ 2018-05-24 15:12 JTechRoad 阅读(153) 评论(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-05-23 13:29 JTechRoad 阅读(105) 评论(0) 推荐(0)