複雜度思考:
Time Complexity: O( log2(N) )
Runtime: 0 ms, Beats: 100%
Memory: 10.10 MB, Beats: 66.35%
33. Search in Rotated Sorted Array
複雜度思考:
Time Complexity: O( log2(N) )
Runtime: 0 ms, Beats: 100%
Memory: 10.10 MB, Beats: 66.35%
複雜度思考:
Time Complexity: O( 2*31 ) (最多)
Runtime: 0 ms, Beats: 100%
Memory: 8.48 MB, Beats: 96.80%
複雜度思考:
Time Complexity: O( N+(N-1)+....+2 )
Runtime: 3 ms, Beats: 71.36%
Memory: 11.29 MB, Beats: 96.48%
19. Remove Nth Node From End of List
複雜度思考:
Time Complexity: O( N )
Runtime: 0 ms, Beats: 100%
Memory: 14.97 MB, Beats: 59.51%
17. Letter Combinations of a Phone Number
複雜度思考:
Time Complexity: O( 4^4 )
Runtime: 0 ms, Beats: 100%
Memory: 8.96 MB, Beats: 95.04%
複雜度思考:
Time Complexity: O( (N-2)*(N-2) )
思考方式:
這題沒想到好方法前一直Time Limit Exceeded, 想到方法後就很簡單。Two Pointers, 一個在最左, 一個在最右, 然後算出容積。如果哪邊桿子比較矮, 就把那邊的桿子向中間移動, 尋找更高的桿子。如果兩邊一樣高, 就一起往內找更高的桿子。
1. 用python寫, 純粹是誤以為線上面試要改用python。後來確認後, 其他題又改回 C++ 來 coding 了。
2. 11_1.py, 跟 11_2.py 剛好可以拿來對比。11_1.py 一次向內移動一格, 而 11_2.py 是往內移動到更高的桿子為止。時間上從 11_1.py 花費 39ms, 進步到 11_2.py 花費 25ms。但我覺得差異不大。
複雜度思考:
10. Regular Expression Matching
思考方式:
其實這題很簡單, 反而難的地方在判斷邊界, 如果反轉後數字超過 int32 的範圍, 要回傳 0。我程式裡的 a10 跟 a01, 就是為了判斷這個而生。
複雜度思考:
因為 0x7FFFFFFF = 2,147,483,647。十進位共10位數
Runtime: 0 ms, Beats: 100%
Memory: 8.47 MB, Beats: 82.10%
難度: Medium
類型: String
==========================
前情題要:
將輸入的字串 s, 用深度numRows的 Zigzag 下去排列, 然後從第一列所有的 chars, 接著第二列, ...., 直到最後一列的 chars讀出來放到另一個字串, 並回傳這個字串。
==========================
5. Longest Palindromic Substring
難度: Medium
類型: Two Pointers, String, Dynamic Programming
CPP程式下載: 5.cpp
==========================
前情題要:
找最長且左右對稱的子字串
==========================
難度: Medium
類型: Hash Table, Math, String
CPP程式下載: 12.cpp
==========================
整數轉羅馬數字
跟 13. Roman to Integer 相反
==========================
前情題要:
==========================