楼主: lchen77
跳转到指定楼层
上一主题 下一主题
收起左侧

New Year, New Start. Leet Code Records (3-5 per day)

🔗
 楼主| lchen77 2019-1-18 15:08:20 | 只看该作者
全局:
2019-01-17:
1). 150 Evaluate Reverse Polish Notation   
2). 152 Maximum Product Subarray   
3). 155 Min Stack  
4). 160 Intersection of Two Linked Lists   
5). 162 Find Peak Element  
6). 163 Missing Ranges  
7). 166 Fraction to Recurring Decimal   
8). 169 Majority Element   
回复

使用道具 举报

🔗
 楼主| lchen77 2019-1-17 15:47:00 | 只看该作者
全局:
2019-01-16:
1). 146 LRU Cache   
2). 148 Sort List   
3). 149 Max Points on a Line   
回复

使用道具 举报

🔗
 楼主| lchen77 2019-1-16 14:54:46 | 只看该作者
全局:
2019-01-15:
1). 138        Copy List with Random Pointer
2). 139        Word Break
3). 140        Word Break II   
4). 141  Linked List Cycle   

Really tired today.
回复

使用道具 举报

🔗
 楼主| lchen77 2019-1-15 13:48:31 | 只看该作者
全局:
2019-01-14:
1). 128 Longest Consecutive Sequence
2). 130 Surrounded Regions
3). 131 Palindrome Partitioning
4). 136. Single Number
5). 134. Gas Station
6). 260 Single Number III
7). 136 Single Number
8). 137 Single Number II
Finally understand single number II, from this post: http://www.cnblogs.com/grandyang/p/4263927.html
  1.     int singleNumber(vector<int>& nums) {
  2.         int a = 0, b = 0;
  3.         for (auto num : nums) {
  4.             b = (b ^ num) & ~a;
  5.             a = (a ^ num) & ~b;
  6.         }
  7.         return b;
  8.     }
复制代码
回复

使用道具 举报

🔗
 楼主| lchen77 2019-1-14 12:34:09 | 只看该作者
全局:
2019-01-13:
1). 105 Construct Binary Tree from Preorder and Inorder Traversal
2). 108 Convert Sorted Array to Binary Search Tree
3). 116 Populating Next Right Pointers in Each Node
4). 118 Pascal's Triangle
5). 121 Best Time to Buy and Sell Stock  
6). 122 Best Time to Buy and Sell Stock II
7). 123. Best Time to Buy and Sell Stock III
8). 188. Best Time to Buy and Sell Stock IV
9). 124. Binary Tree Maximum Path Sum
10). 125. Valid Palindrome
11). 127 Word Ladder
post the one that I have improved, from one direction to two directions
  1. class Solution {
  2. public:
  3.     int ladderLength(string beginWord, string endWord, vector<string>& wordList) {
  4.         unordered_set<string> dict(wordList.begin(), wordList.end());
  5.         if (dict.find(endWord) == dict.end()) return 0;
  6.         unordered_set<string> head{beginWord}, tail{endWord};
  7.         int steps = 2;
  8.         while (!head.empty() && !tail.empty()) {
  9.             if (head.size() > tail.size()) swap(head, tail);
  10.             unordered_set<string> next_set;
  11.             for (auto str : head) dict.erase(str);
  12.             for (auto str : head) {
  13.                 for (int i = 0; i < str.size(); i++) {
  14.                     char tmp = str[i];
  15.                     for (char ch = 'a'; ch <= 'z'; ch++) {
  16.                         if (ch == tmp) continue;
  17.                         str[i] = ch;
  18.                         if (tail.find(str) != tail.end()) return steps;
  19.                         if (dict.find(str) != dict.end()) {
  20.                             next_set.insert(str);
  21.                             dict.erase(str);
  22.                         }
  23.                     }
  24.                     str[i] = tmp;
  25.                 }
  26.             }
  27.             steps++;
  28.             swap(next_set, head);     
  29.         }
  30.         return 0;
  31.     }
  32. };
复制代码

回复

使用道具 举报

🔗
 楼主| lchen77 2019-1-13 13:52:46 | 只看该作者
全局:
2019-01-12:
1). 76. Minimum Window Substring
2). 78. Subsets
3). 79. Word Search
4). 84. Largest Rectangle in Histogram
5). 88. Merge Sorted Array
6). 91. Decode Ways
7). 94. Binary Tree Inorder Traversal
8). 98. Validate Binary Search Tree
9). 101. Symmetric Tree
10). 102. Binary Tree Level Order Traversal
11). 103. Binary Tree Zigzag Level Order Traversal
12). 104. Maximum Depth of Binary Tree
回复

使用道具 举报

🔗
 楼主| lchen77 2019-1-12 13:53:11 | 只看该作者
全局:
2019-01-11
happy Friday Day, and have a rest:
1). 76. Minimum Window Substring
and find a better solution:
  1.    string minWindow(string s, string t) {
  2.         unordered_map<char, int> expected;
  3.         for (auto ch : t) expected[ch]++;
  4.         int lenT = t.size(), min_win = s.size() + 1, idx_start = 0, idx_m = -1;
  5.         for (int i = 0; i < s.size(); i++) {
  6.             if (expected[s[i]]-- > 0) lenT--;
  7.             while (lenT == 0) {
  8.                 if (i - idx_start + 1 < min_win) {
  9.                     min_win = i - idx_start + 1;
  10.                     idx_m = idx_start;
  11.                 }
  12.                
  13.                 if (++expected[s[idx_start++]] > 0) lenT++;
  14.             }
  15.         }
  16.         return idx_m == -1 ? "" : s.substr(idx_m, min_win);
  17.     }
  18. };
复制代码


回复

使用道具 举报

🔗
 楼主| lchen77 2019-1-11 15:34:00 | 只看该作者
全局:
2019-01-10

1). 55. Jump Game
2). 56. Merge Intervals
3). 62. Unique Paths
4). 66. Plus One
5). 69. Sqrt(x)
6). 70. Climbing Stairs
7). 75. Sort Colors
回复

使用道具 举报

🔗
 楼主| lchen77 2019-1-10 15:02:51 | 只看该作者
全局:
2019-01-09:
1). 48. Rotate Image
2). 49. Group Anagrams
3). 50. Pow(x, n)   
4). 53. Maximum Subarray
5). 54. Spiral Matrix
回复

使用道具 举报

🔗
 楼主| lchen77 2019-1-9 13:39:09 | 只看该作者
全局:
2019-01-08
1). 41.First Missing Positive
2). 42.Trapping Rain Water
3). 43. Multiply Strings
4). 44. Wildcard Matching
5). 46. Permutations
6). 31. Next Permutation
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表