Press "Enter" to skip to content

Huahua's Tech Road

成为更好的自己,2020再出发

时光飞逝,转眼2019年就过去了,我们迎来了一个崭新的十年,花花在这里祝大家新年快乐!在过去的一年里面,发生了很多事,国际上的、国内的、还是花花自身上的,与其说是多事之秋,我觉得更像是好事多磨。无论是过去的2019年还是已经到来的2020年都会是不平凡的一年,被载入人类的史册。(开头开的太宏大了,我都快写不下去了…)

让我们来看看花花去年年末时候给自己的定的小目标吧:

  • YouTube订阅9.7K -> 20K,实际24K,2.4x
  • B站粉丝832 -> 3K,实际11K,12.3x
  • 公众号订阅2.9K -> 5k,实际8.9K,3.1x

没有唬人的标题,没有博眼球的封面,没有大尺度的内容,有的只是便于搜索的题号和题名,万年不变的PPT封面,和枯燥/口齿不清的念白。感谢同学们的不离不弃,全部以指数形式增长(这个时间复杂度有点高啊)。2019年我播种了超过100个视频,收获的是同学们拿到了offer脱离苦海成功上岸的喜悦、感谢信和红包,以及大家的支持与祝福。

除了讲题之外,2019年花花还完成了哪些小目标呢?工作上:晋升,虽然package没涨多少、自己带的实习生也拿到了return offer,感觉很欣慰。生活上:买房,两人合力存了两年多的钱,终于凑够了首付在相当于国内三、四线城市的湾区很偏的地方买了一套小房子。虽然背上了30年的贷款,但总算是敢花钱了:买电视,买家具,智能家居设备,换了新电脑,来了一场说走就走的旅行。相信很多人和我一样,在没买房之前真是喘不过气来,一分钱都不敢乱花。在成为房主之后很快就解锁了很多新技能:水管工、电工、木工、水泥工、油漆工、园艺工。。。以后再和大家慢慢分享经验。2019年也是我的VLOG元年,我原本是一个很快的人。拍摄VLOG让我慢下来,让我能够更仔细地去观察事物,更多地从他人的角度去看待这个世界。

当然2019年也有不少遗憾:三年没有回国了,国内发展日新月异,感觉我已经完全落伍了。长辈们慢慢老去,同龄人聚会结婚生子,这些片段都没有我的存在。跟着我十多年的手机号也由于欠费超过三个月而被注销。连续第三年减肥失败,体重倒是没有增长,但就是减不下来,看来要每天打卡健身环了。在美国待了7年了,英语口语还是没有太大地提高,自己不喜欢说话能怪组里中国人太多吗?没时间读书,通过实践能掌握不少东西,但是理论学习还是不可或缺的,不然你能够达到的高度是有限的。

说了这么多自己的事情是希望打破大家对我的刻板印象,但我相信在下个讲题视频那个一板一眼的花花马上就回来了。

2020年为成为更好的自己再出发,一大波讲题视频正在路上。当然还是要给自己定了几个小目标:每周2个视频,YouTube 40K,B站25K,公众号15K,我们明年这个时候再来检验一下。

花花酱 LeetCode 2. Add Two Numbers

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

Example:

Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
Explanation: 342 + 465 = 807.

Solution: Simulation

Time complexity: O(max(n,m))
Space complexity: O(max(n,m))

C++

Java

Python3

花花酱 LeetCode 1306. Jump Game III

Given an array of non-negative integers arr, you are initially positioned at start index of the array. When you are at index i, you can jump to i + arr[i] or i - arr[i], check if you can reach to any index with value 0.

Notice that you can not jump outside of the array at any time.

Example 1:

Input: arr = [4,2,3,0,3,1,2], start = 5
Output: true
Explanation: 
All possible ways to reach at index 3 with value 0 are: 
index 5 -> index 4 -> index 1 -> index 3 
index 5 -> index 6 -> index 4 -> index 1 -> index 3 

Example 2:

Input: arr = [4,2,3,0,3,1,2], start = 0
Output: true 
Explanation: 
One possible way to reach at index 3 with value 0 is: 
index 0 -> index 4 -> index 1 -> index 3

Example 3:

Input: arr = [3,0,2,1,2], start = 2
Output: false
Explanation: There is no way to reach at index 1 with value 0.

Constraints:

  • 1 <= arr.length <= 5 * 10^4
  • 0 <= arr[i] < arr.length
  • 0 <= start < arr.length

Solution: BFS / DFS

Time complexity: O(n)
Space complexity: O(n)

C++

花花酱 LeetCode 1305. All Elements in Two Binary Search Trees

Given two binary search trees root1 and root2.

Return a list containing all the integers from both trees sorted in ascending order.

Example 1:

Input: root1 = [2,1,4], root2 = [1,0,3]
Output: [0,1,1,2,3,4]

Example 2:

Input: root1 = [0,-10,10], root2 = [5,1,7,0,2]
Output: [-10,0,0,1,2,5,7,10]

Example 3:

Input: root1 = [], root2 = [5,1,7,0,2]
Output: [0,1,2,5,7]

Example 4:

Input: root1 = [0,-10,10], root2 = []
Output: [-10,0,10]

Example 5:

Input: root1 = [1,null,8], root2 = [8,1]
Output: [1,1,8,8]

Constraints:

  • Each tree has at most 5000 nodes.
  • Each node’s value is between [-10^5, 10^5].

Solution: Inorder traversal + Merge Sort

Time complexity: O(t1 + t2)
Space complexity: O(t1 + t2)

C++

C++/STL

花花酱 LeetCode 1304. Find N Unique Integers Sum up to Zero

Given an integer n, return any array containing n unique integers such that they add up to 0.

Example 1:

Input: n = 5
Output: [-7,-1,1,3,4]
Explanation: These arrays also are accepted [-5,-1,1,2,3] , [-3,-1,2,-2,4].

Example 2:

Input: n = 3
Output: [-1,0,1]

Example 3:

Input: n = 1
Output: [0]

Constraints:

  • 1 <= n <= 1000

Solution: Generation

Use numbers from {-n/2, … n/2} + {0 if n is odd}

Time complexity: O(n)
Space complexity: O(1)

C++