📣 独立日限时特惠: VIP通行证立减$68
查看: 3276| 回复: 38
跳转到指定楼层
上一主题 下一主题
收起左侧

zzzzzzzy 刷题记录帖 🤓

全局:

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

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

x
刷题记录 之前放在自己blog 里,想了想 还是开个帖子吧~~ 嘿嘿嘿
附上 之前 刷题记录

希望每天至少5题+independent project,搞到拿到offer


### Jun 5, 2018

**LintCode:** Naive

- [x] 37. Reverse 3-digit Integer
- [x] 145. Lowercase to Uppercase
- [x] 366. Fibonacci


### Jun 12, 2018

**LeetCode:** Database

- [x] Big Countries


### Jun 14, 2018

**LeetCode:** Database

- [x] Swap Salary
- [x] Not Boring Movies
- [x] Duplicate Emails
- [x] Combine Two Tables


### Jun 15, 2018

**LeetCode:** Database

- [x] Employees Earning More Than Their Managers
- [x] Classes More Than 5 Students
- [x] Customers Who Never Order
- [x] Rising Temperature
- [x] Delete Duplicate Emails
- [x] Second Highest Salary
- [x] Exchange Seats


### Jun 16, 2018

**LintCode:** Naive

- [x] 452. Remove Linked List Elements
- [x] 454. Rectangle Area
- [x] 463. Sort Integers
- [x] 466. Count Linked List Nodes
- [x] 479. Second Max of Array
- [x] 484. Swap Two Integers in Array
- [x] 632. Binary Tree Maximum Node
- [x] 763. Hex Conversion


### Jun 18, 2018

**LeetCode:** Database

- [x] Consecutive Numbers       
- [x] Department Highest Salary
- [x] Rank Scores       


### Jul 7, 2018

**LintCode:** Binary Search

- [x] 14. First Position of Target
- [x] 141. Sqrt(x)
- [x] 159. Find Minimum in Rotated Sorted Array
- [x] 17. Subsets
- [x] 62. Search in Rotated Sorted Array
- [x] 74. First Bad Version
- [x] 75. Find Peak Element
- [x] 183. Wood Cut
- [x] 669. Coin Change

**LeetCode:** Binary Search

- [x] 69. Sqrt(x)
- [x] 33. Search in Rotated Sorted Array
- [x] 162. Find Peak Element
- [x] 322. Coin Change


### Jul 8, 2018

**SQL Exercises**

- [x] The computer store
- [x] Employee management

**LintCode:** Binary Tree `&&` Divide Conquer

- [x] **66. Binary Tree Preorder Traversal**
- [x] **67. Binary Tree Inorder Traversal**
- [x] **68. Binary Tree Postorder Traversal**
- [x] 97. Maximum Depth of Binary Tree
- [x] 480. Binary Tree Paths
- [x] 93. Balanced Binary Tree
- [x] 453. Flatten Binary Tree to Linked List


### Jul 9, 2018

**SQL Exercises**

- [x] The warehouse

**LintCode:**  Binary Search `||` Binary Tree `&&` Divide Conquer

- [x] 596. Minimum Subtree
- [x] 1219. Heaters
- [x] 28. Search a 2D Matrix
- [x] 547. Intersection of Two Arrays
- [x] 988. Arranging Coins
- [x] 457. Classical Binary Search
- [x] 60. Search Insert Position
- [x] 662. Guess Number Higher or Lower


### Jul 10, 2018

**LintCode:**  Binary Tree `&&` Divide Conquer

- [x] 595. Binary Tree Longest Consecutive Sequence
- [x] 614. Binary Tree Longest Consecutive Sequence II
- [ ] 619. Binary Tree Longest Consecutive Sequence III
- [x] 88. Lowest Common Ancestor of a Binary Tree
- [x] 376. Binary Tree Path Sum
- [ ] 246. Binary Tree Path Sum II
- [ ] 472. Binary Tree Path Sum III
- [ ] 863. Binary Tree Path Sum IV

**SQL Exercises**

- [x] Movie theatres


### Jul 11, 2018

**LintCode:**  Breadth-First-Search

- [x] **69. Binary Tree Level Order Traversal**
- [x] **70. Binary Tree Level Order Traversal II**
- [x] 433. Number of Islands
- [x] 7. Serialize and Deserialize Binary Tree
- [x] 127. Topological Sorting
- [x] 615. Course Schedule

**SQL Exercises**

- [x] Pieces and providers
- [x] Scientists
- [x] Planet Express


### Jul 12, 2018

**LintCode:**  Breadth-First-Search

- [x] 616. Course Schedule II
- [x] 242. Convert Binary Tree to Linked Lists by Depth
- [x] 71. Binary Tree Zigzag Level Order Traversal
- [x] 178. Graph Valid Tree
- [x] 137. Clone Graph
- [x] 618. Search Graph Nodes


### Jul 13, 2018

**LintCode:**  Breadth-First-Search

- [x] 598. Zombie in Matrix
- [x] 611. Knight Shortest Path
- [x] 605. Sequence Reconstruction


### Jul 14, 2018

**LintCode:**  Depth-First-Search

- [ ] 40. Implement Queue by Two Stacks


### Jul 15, 2018

**LintCode:**  Depth-First-Search

- [x] 135. Combination Sum
- [x] 153. Combination Sum II
- [ ] 564. Combination Sum IV
- [x] 136. Palindrome Partitioning
- [x] 15. Permutations
- [x] 16. Permutations II
- [x] 33. N Queens


### Jul 16, 2018

**LintCode:**  Linked List & Array

- [x] 35. Reverse Linked List
- [x] 102. Linked List Cycle
- [ ] 103. Linked List Cycle II


### Jul 17, 2018

**LintCode:**  Linked List & Array

- [x] 380. Intersection of Two Linked Lists
- [x] 36. Reverse Linked List II (dummy node)
- [x] 41. Maximum Subarray
- [x] 6. Merge Two Sorted Arrays


### Jul 18, 2018

**LintCode:**  Linked List & Array

- [x] 450. Reverse Nodes in k-Group
- [x] 105. Copy List with Random Pointer **[高频题]**
- [x] 604. Window Sum
- [x] 138. Subarray Sum
- [x] 139. Subarray Sum Closest
- [x] 372. Delete Node in a Linked List
- [x] 547. Intersection of Two Arrays
- [x] 65. **Median of two Sorted Arrays**


### Jul 19, 2018

**LintCode:**  Two Pointers

- [x] 539. Move Zeroes
- [x] 521. Remove Duplicate Numbers in Array
- [x] 415. Valid Palindrome
- [x] **31. Partition Array**
- [x] 608. Two Sum II - Input array is sorted


### Jul 20, 2018

**LintCode:**  Two Pointers

- [x] 373. Partition Array by Odd and Even
- [x] 144. Interleaving Positive and Negative Numbers
- [x] 49. Sort Letters by Case
- [x] 609. Two Sum - Less than or equal to target
- [x] 443. Two Sum - Greater than target
- [x] 8. Rotate String


### Jul 21, 2018

**LintCode:**  Two Pointers `&&` Quick Select

- [x] 461. Kth Smallest Numbers in Unsorted Array
- [x] 148. Sort Colors
- [x] 143. Sort Colors II


### Jul 24, 2018

**LintCode:**

- [x] 764. Calculate Circumference And Area






补充内容 (2018-8-2 22:56):
SQL 的“简单题”在这里 https://github.com/Zhenye-Na/SQL-Exercises

补充内容 (2018-8-3 02:46):
在 Heroku deploy 了第一个["水"]项目 https://qac.herokuapp.com/ 并且写了一个 blog https://zhenye-na.github.io/2018 ... -app-to-heroku.html

补充内容 (2018-8-3 02:52):
今天开始跟 The Web Developer Bootcamp + 做项目 ( ु•⌄• )و✧

补充内容 (2018-8-15 09:26):

webdev bootcamp 跟完啦,deploy 在这里 https://demo-mkplc.herokuapp.com/, 要在这个基础上自己增加一些其它功能 ,准备开始学 Pyspark 啦 有机不错的 proj 的点子,趁还没开学,在挣扎一下 !!

评分

参与人数 2大米 +8 收起 理由
PeaceAmber + 3 给你点个赞!
1点50分 + 5 给你点个赞!

查看全部评分


上一篇:打卡flag
下一篇:求看作文
推荐
 楼主| Pro MacBook 2018-8-23 12:07:14 | 只看该作者
全局:
然后是今天哒~~ 今天学习一下 新的 数据结构 Fenwick Tree / Binary Indexed Tree 用来解决 Prefix Sum 这种问题~~ 然后总结了一下放在自己的 blog 里辣

吐槽一下 lintcode 还有 隐藏题目 真的是 666


- [x] 596. Minimum Subtree (隐藏题)
- [x] 988. Arranging Coins (**Binary Search** + **Arithmetic Sequence**)
- [x] 1219. Heaters (**Binary Search**)
- [x] 840. Range Sum Query - Mutable (**Fenwick Tree / Binary Indexed Tree**)



补充内容 (2018-9-23 14:52):
踩个鸡儿?爱看不看好嘛???
回复

使用道具 举报

推荐
 楼主| Pro MacBook 2018-8-3 02:47:08 | 只看该作者
全局:
肥宅快乐水 发表于 2018-8-3 00:42
为什么只更新到7/244

呼 自己默默搬家+做项目 这就补上
回复

使用道具 举报

推荐
 楼主| Pro MacBook 2018-8-13 14:33:19 | 只看该作者
全局:
今天做 3Sum 的时候 第一反应没有想到 用 2Sum 来解决而是用 Binary Search 来去找中间那个数,但是发现 “自己能力不足,代码写出来又臭又长,过不了”挂出来接受各位大佬批评指正!!
还希望各位能够看一下,指出自己写的错误的地方!!

下面贴上代码


Binary Search + Two Pointers

代码思路是这样的
  • 首先排序,不然没办法判断多了还是少了
  • 然后取出 头尾,在中间 Binary Search 一下,找到了就返回 `index`,找不到就返回 `-1`
  • 然后就要移动 头尾指针,因为会有重复,所以有一个“象征性去重”的过程



  1. public class Solution {
  2.     /**
  3.      * @param numbers: Give an array numbers of n integer
  4.      * @return: Find all unique triplets in the array which gives the sum of zero.
  5.      */
  6.     public List<List<Integer>> threeSum(int[] numbers) {
  7.         // write your code here
  8.         List<List<Integer>> result = new ArrayList<List<Integer>>();
  9.         if (numbers == null || numbers.length < 3) {
  10.             return result;
  11.         }

  12.         Arrays.sort(numbers);
  13.         int start = 0, end = numbers.length - 1;
  14.         while (start < end) {
  15.             List<Integer> combination = new ArrayList<>();

  16.             int target = 0 - (numbers[start] + numbers[end]);
  17.             int idx = binarySearch(numbers, target, start, end);

  18.             if (idx != -1) {
  19.                 combination.add(numbers[start]);
  20.                 combination.add(numbers[idx]);
  21.                 combination.add(numbers[end]);
  22.                 result.add(combination);
  23.                 start++;
  24.                 while (start >= 0 && numbers[start] == numbers[start + 1]) {
  25.                     start++;
  26.                 }
  27.                 end--;
  28.                 while (end <= numbers.length - 1 && numbers[end] == numbers[end - 1]) {
  29.                     end--;
  30.                 }
  31.             } else {
  32.                 if (-target < 0) {
  33.                     start++;
  34.                 } else {
  35.                     end--;
  36.                 }
  37.             }
  38.         }

  39.         return result;
  40.     }


  41.     private int binarySearch(int[] nums, int target, int start, int end) {

  42.         while (start + 1 < end) {
  43.             int mid = (end - start) / 2 + start;

  44.             if (target == nums[mid]) {
  45.                 return mid;
  46.             } else if (target < nums[mid]) {
  47.                 end = mid;
  48.             } else {
  49.                 start = mid;
  50.             }
  51.         }

  52.         if (target == nums[start]) {
  53.             return start;
  54.         }

  55.         if (target == nums[end]) {
  56.             return end;
  57.         }

  58.         return -1;
  59.     }

  60. }
复制代码





Input
[-8,-8,-8,-5,-4,-1,-1,0,1,2,3,4,5,7]

Output
[[-8,1,7],[-8,3,5],         [-5,1,4],                            [-4,1,3],[-1,-1,2]]

Expected
[[-8,1,7],[-8,3,5],[-5,0,5],[-5,1,4],[-5,2,3],[-4,-1,5],[-4,0,4],[-4,1,3],[-1,-1,2],[-1,0,1]]


根据输出可以发现问题所在,以`-8`开头,`5`结尾的找到之后,会 `start++`,`end--`,然而 存在另一个仍然以`5`结尾的解,被程序直接跳过了

回复

使用道具 举报

全局:
为什么只更新到7/244

评分

参与人数 1大米 +5 收起 理由
Pro MacBook + 5 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
 楼主| Pro MacBook 2018-8-9 08:06:58 | 只看该作者
全局:
Update:

### Aug 6, 2018

**LintCode:** Data Structure `&&` Dynamic Programming

- [x] 517. Ugly Number


### Aug 7, 2018

**LintCode:** Tag: Basic Implementation

- [x] 30. Insert Interval
- [x] 55. Compare Strings
- [x] 9. Fizz Buzz
- [x] 170. Rotate List
- [x] 13. Implement strStr()
- [x] 78. Longest Common Prefix


Related Problems:

- [ ] 156. Merge Intervals


### Aug 8, 2018

**LintCode:** Tag: Binary Search

- [x] 548. Intersection of Two Arrays II
- [x] 61. Search for a Range **Binary Search integrates First Position and Last Position together**
- [x] 76. Longest Increasing Subsequence **Dynamic Programming `||` Binary Search**
- [x] 160. Find Minimum in Rotated Sorted Array II **Binary Search `&&` Two Pointers**

祝贺自己成功刷完了人生中第100题 233,自己做了excel表格记录

补充内容 (2018-8-9 12:28):
github: https://github.com/Zhenye-Na/LxxxCode
回复

使用道具 举报

🔗
 楼主| Pro MacBook 2018-8-10 11:27:29 | 只看该作者
全局:
### Aug 9, 2018

**LintCode:** Ladder - String

- [x] 171. Anagrams
- [x] 158. Valid Anagram
- [x] 1038. Jewels and Stones
- [x] 77. Longest Common Subsequence **Dynamic Programming**
- [x] 79. Longest Common Substring **Dynamic Programming**


今天学习到的知识点有:

Java
  • ArrayList<>() and LinkedList<>()
  • ArrayList remove() method
  • compare a string with the empty string ("") in java
  • String.toCharArray()
  • String.valueOf()
  • Map.entrySet()
  • entry.getValue()
  • ArrayList.addAll()


Python
  • collections.Counter()



推荐两个 Youtube Channel




回复

使用道具 举报

🔗
 楼主| Pro MacBook 2018-8-11 12:08:24 | 只看该作者
全局:
### Aug 10, 2018

**LintCode:** Ladder - Integer Array

- [x] 100. Remove Duplicates from Sorted Array
- [x] 101. Remove Duplicates from Sorted Array II
- [x] 172. Remove Element
- [x] 50. Product of Array Exclude Itself
- [x] 189. First Missing Positive
- [x] 54. String to Integer (atoi)

**LeetCode:** Database

- [x] 577.Employee Bonus

从昨天就已经开始练习 首先在白纸 (没有白板)写思路,过程,需要考虑的东西,今天看了个视频 可能对转专业越来越不友好了,定个目标刷他个 400 题吧

加油!

回复

使用道具 举报

🔗
 楼主| Pro MacBook 2018-8-12 14:07:53 | 只看该作者
全局:
### Aug 11, 2018

**LintCode:** Ladder - Integer Array

- [x] 64. Merge Sorted Array
- [x] 56. Two Sum

今天听了 linghuchong 的公开课。。。要不要换成Python刷题, 啊 纠结!

今天又改了一下简历,挂在地里了

加油加油!

回复

使用道具 举报

🔗
 楼主| Pro MacBook 2018-8-13 14:29:12 | 只看该作者
全局:
### Aug 12, 2018

**LintCode:** Ladder - Integer Array

- [x] 57. 3Sum
- [x] 59. 3Sum Closest
- [x] 31. Partition Array
- [x] 139. Subarray Sum Closest
- [x] 58. 4Sum

从明天开始抛弃 Java 改用 Python 刷题啦~

回复

使用道具 举报

🔗
1点50分 2018-8-13 19:50:59 | 只看该作者
全局:
这是按照什么顺序刷滴

评分

参与人数 1大米 +5 收起 理由
Pro MacBook + 5 谢谢你的米!

查看全部评分

回复

使用道具 举报

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

本版积分规则

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