# 演算法作業 HW6 ## 1. Huffman Code  * 符號的Huffman code * A: 0110 * B: 00 * C: 0111 * D: 010 * E: 110 * F: 10 * G: 111 * * 解碼後 * 110 0110 111 * EAG ## 2. 隔出最多的水 * 花費時間: 約40分鐘 * 自己寫的程度: 用了Solution * 想法: 用左右兩邊去比較,右邊高度比左邊高度大即縮減左標,反之則縮減右標。  ```python= class Solution: def maxArea(self, height: List[int]) -> int: l , r , ans = 0, len(height)-1 , 0 while l <= r: ans=max(answer,area) area= min(height[r],height[l]) * (r-l) if height[r]>height[l]: l+=1 else: r-=1 return ans ``` ## 3. 跳到最後-V2 ### Jump Game 2 - LeetCode * 寫程式所花費的時間: 約30分鐘 * 自己寫的程度: Solution找答案 * 解題思路: 利用二搜法找到最好的路徑。 *  ```python= class Solution: def jump(self, nums: List[int]) -> int: ans = 0 l , r = 0 , 0 while r < len(nums) - 1: distance = 0 for i in range(l, r + 1): distance = max(distance, i + nums[i]) l=r+1 r=distance ans+=1 return ans ``` ## 心得 這次的期中考覺得自己沒有考的很好 希望自己可以再更努力
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up