查看: 3050| 回复: 40
跳转到指定楼层
上一主题 下一主题
收起左侧

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

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
The goal is here:
1). 3-5 per day at weekdays
2). 10 - 15 per day at weekends
Welcome other friends to join and let us keep up together.

评分

参与人数 3大米 +6 收起 理由
捕鱼大神 + 1 你好棒啊!每天都做那么多题!
QiaPiaQiuPiu + 2 给你点个赞!
junj0619 + 3 给你点个赞!

查看全部评分


上一篇:2019年5月毕业,倒计时138天,记录刷题找工,求offer!
下一篇:今天开个刷题记录贴,给自己定个目标
推荐
 楼主| 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-7 12:54:45 | 只看该作者
全局:
2019-01-06
1). 17. Letter Combinations of a Phone Number
2). 19. Remove Nth Node From End of List
3). 20. Valid Parentheses
4). 21. Merge Two Sorted Lists
5). 22. Generate Parentheses
6). 23. Merge k Sorted Lists
7). 26. Remove Duplicates from Sorted Array
8). 28. Implement strStr()
9). 29. Divide Two Integers
10). 33. Search in Rotated Sorted Array
This is the second round, post the one that improved.
  1. class Solution {
  2. public:
  3.     int strStr(string haystack, string needle) {
  4.         const int size_h = haystack.size();
  5.         const int size_n = needle.size();
  6.         if (0 == size_n) return 0;
  7.         vector<int> lps(size_n, 0);
  8.         for (int i = 1; i < size_n; i++) {
  9.             int pos = lps[i-1];
  10.             while (pos > 0 && needle[pos] != needle[i]) pos = lps[pos - 1];
  11.             if (needle[pos] == needle[i]) lps[i] = pos + 1;
  12.         }
  13.         int idx_h = 0, idx_n = 0;
  14.         for (; idx_h < size_h; idx_h++) {
  15.             while (idx_n > 0 && needle[idx_n] != haystack[idx_h]) idx_n = lps[idx_n - 1];
  16.             if (needle[idx_n] == haystack[idx_h]) idx_n++;
  17.             if (idx_n == size_n) return idx_h - size_n + 1;
  18.         }
  19.         return -1;
  20.     }
  21. };
复制代码
回复

使用道具 举报

推荐
 楼主| 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-3-6 15:45:57 | 只看该作者
全局:
2019-03-05:
1). 341. Flatten Nested List Iterator
2). 759. Employee Free Time
3). 756. Pyramid Transition Matrix
4). 42. Trapping Rain Water
5). 76. Minimum Window Substring
6). 1. Two Sum
7). 829. Consecutive Numbers Sum
回复

使用道具 举报

🔗
 楼主| lchen77 2019-3-6 13:29:59 | 只看该作者
全局:
imiochen24 发表于 2019-3-5 21:42
大家一天刷个十几题怎么办到的

一般是周末刷个十几题, 还有就是那些题不是刷第一遍。
加油
回复

使用道具 举报

🔗
imiochen24 2019-3-5 21:42:58 | 只看该作者
全局:
大家一天刷个十几题怎么办到的
回复

使用道具 举报

🔗
 楼主| lchen77 2019-3-5 16:08:46 | 只看该作者
全局:
2019-03-03:
1). 843. Guess the Word
2). 755. Pour Water
3). 336. Palindrome Pairs
4). 269. Alien Dictionary
5). 773. Sliding Puzzle

2019-03-04:
1). 371. Sum of Two Integers
2). 751. IP to CIDR
3). 251. Flatten 2D Vector
4). 39. Combination Sum
5). 324. Wiggle Sort II
回复

使用道具 举报

🔗
 楼主| lchen77 2019-3-3 15:50:41 | 只看该作者
全局:
2019-03-02:
1). 364. Nested List Weight Sum II
2). 365. Water and Jug Problem
3). 366. Find Leaves of Binary Tree
4). 368. Largest Divisible Subset
5). 370. Range Addition
6).  773. Sliding Puzzle
7). 751. IP to CIDR
8). 756. Pyramid Transition Matrix
9). Consecutive Numbers Sum
10). 815. Bus Routes
11). 16. 3Sum Closest
回复

使用道具 举报

🔗
 楼主| lchen77 2019-2-28 14:20:30 | 只看该作者
全局:
2019-02-28:
1). 350. Intersection of Two Arrays II
2). 349. Intersection of Two Arrays
3). 351. Android Unlock Patterns
4). 351. Android Unlock Patterns
5). 359. Logger Rate Limiter
6). 354. Russian Doll Envelopes
7). 356. Line Reflection
8). 358. Rearrange String k Distance Apart
回复

使用道具 举报

🔗
 楼主| lchen77 2019-2-26 16:31:08 | 只看该作者
全局:
2019-02-26:
1). 337. House Robber III
2). 338. Counting Bits
3). 339. Nested List Weight Sum
4). 340. Longest Substring with At Most K Distinct Characters
5). 341. Flatten Nested List Iterator
6). 342. Power of Four
7). 343. Integer Break
8). 344. Reverse String
9). 345. Reverse Vowels of a String
10).346. Moving Average from Data Stream
11). 347. Top K Frequent Elements
回复

使用道具 举报

🔗
 楼主| lchen77 2019-2-25 13:13:51 | 只看该作者
全局:
2019-02-24:
1). 307. Range Sum Query - Mutable
2). 308. Range Sum Query 2D - Mutable
3). 309. Best Time to Buy and Sell Stock with Cooldown
4). 310. Minimum Height Trees
5). 311. Sparse Matrix Multiplication
6). 312. Burst Balloons
7). 313. Super Ugly Number
8). 314. Binary Tree Vertical Order Traversal
9). 317. Shortest Distance from All Buildings
10).318. Maximum Product of Word Lengths
11). 320. Generalized Abbreviation
12). 323. Number of Connected Components in an Undirected Graph
13). 325. Maximum Size Subarray Sum Equals k
14). 326. Power of Three
15). 327. Count of Range Sum
16). 328. Odd Even Linked List
回复

使用道具 举报

🔗
 楼主| lchen77 2019-2-24 16:29:07 | 只看该作者
全局:
2019-02-24:
1). 42. Trapping Rain Water
2). 84. Largest Rectangle in Histogram
3). 94. Binary Tree Inorder Traversal
4). 101. Symmetric Tree
5). 301. Remove Invalid Parentheses
6). 302. Smallest Rectangle Enclosing Black Pixels
7). 303. Range Sum Query - Immutable
8). 304. Range Sum Query 2D - Immutable
9). 305. Number of Islands II
10). 306. Additive Number

回复

使用道具 举报

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

本版积分规则

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