###### tags: `阿瑜` # Day 8: Recap Day [1-7] & Enhance | Day# | Title | Level | | ---- | ----- | ----- | | 1 | [Day 1: Let's start !](https://ithelp.ithome.com.tw/articles/10265412) | None | | 2 | [Day 2: LeetCode 978. Longest Turbulent Subarray](https://ithelp.ithome.com.tw/articles/10265787) | Medium | | 3 | [Day 3: LeetCode 995. Minimum Number of K Consecutive Bit Flips](https://ithelp.ithome.com.tw/articles/10267119) | Hard | | 4 | [Day 4: LeetCode 995. Minimum Number of K Consecutive Bit Flips(v2)](https://ithelp.ithome.com.tw/articles/10267861) | Hard | | 5 | [Day 5: LeetCode 88. Merge Sorted Array](https://ithelp.ithome.com.tw/articles/10268486) | Easy | | 6 | [Day 6: LeetCode 54. Spiral Matrix](https://ithelp.ithome.com.tw/articles/10269135) | Medium | | 7 | [Day 7: LeetCode 485. Max Consecutive Ones](https://ithelp.ithome.com.tw/articles/10269725) | Easy | ### Enhance - [x] Day 2: LeetCode 978. Longest Turbulent Subarray - 思路(from Discuss) - either up or down **begin** - 🔼 🔽 🔼 🔽 ... - 🔽 🔼 🔽 🔼 ... - 繼承上一次(inc/dec)的數量,再加一 - 程式碼 ```python class Solution: def maxTurbulenceSize(self, arr: List[int]) -> int: inc = 1 dec = 1 res = 1 for i in range(1,len(arr)): if arr[i] > arr[i-1]: inc = dec+1 dec = 1 elif arr[i] < arr[i-1]: dec = inc+1 inc = 1 else: inc = 1 dec = 1 print("i-inc-dec:",i,inc,dec) #res = max(inc,dec) res = max([inc,dec,res]) print("res:",res) return res ``` - Reference - [神人解-Java O(N) time O(1) space](https://leetcode.com/problems/longest-turbulent-subarray/discuss/221935/Java-O(N)-time-O(1)-space) ### What's more? 1. 每月挑戰(2021.09.22) - [(Medium) LeetCode 1239. Maximum Length of a Concatenated String with Unique Characters](https://leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters/) - 題意 - 求unique的**最長**長度 - unique's element 怎麼組成? Ans: 自己碰其他element所組成 1. 自己中的每個character需unique 2. 碰其他時也需unique - 思路 - List 中的每個element(set)都是不同組合,在組合中找最長長度 - Python-set() Check 自己中是否有重複element - 碰前的Check:是否有一樣的character→使用`&` - 碰(**concate**)所用的運算子`|` - Reference - [花花醬-YT圖解](https://youtu.be/N7womGmLXh8)  - 程式碼 ```python class Solution: def maxLength(self, arr: List[str]) -> int: A = [set()] # set() => {} for a in arr: if len(set(a))!=len(a): continue for element in A[:]: if set(a)&element: continue A.append(set(a)|element) print(A) maxLen = (-1) for _ in A: if len(_)>maxLen: maxLen = len(_) return maxLen ``` 3. 目的刷 - [(Easy) LeetCode 104. Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) - 思路 - BFS-**Queue** - Initial: Queue 先加root 1. 直到Queue為空 - ans(Heigh)++ 3. Iterate(遍歷)每一層節點 - 移除遍歷節點 - 加入遍歷節點的child節點 - We+夥伴 - [soft解(C language)](https://ithelp.ithome.com.tw/articles/10269862) - [Casey解(Python)](https://ithelp.ithome.com.tw/articles/10270148) - 其他 - [Iterative Method to find Height of Binary Tree](https://www.google.com/amp/s/www.geeksforgeeks.org/iterative-method-to-find-height-of-binary-tree/amp/) ### What's Next? > 面試: > Find Good Job!
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.