下周要面試了,程式考C,只好緊急刷題來喚醒跟C語言的回憶。
刷題列表參考:LeetCode面試必刷總復習題 | Tech Interview Prep
參考影片:這個作者用python解題但講得很詳細,我都是參考他的解題思路,然後在leetcode討論區找C的code來看,看完覺得有寫的價值再自己寫一遍。
LeetCode力扣面試必刷總復習 - 上篇 | 給要準備面試不知道從何刷起的你 | 給想要重新復習的面試老司機 | Python
LeetCode力扣面試必刷總復習 - 下篇 | 給要準備面試不知道從何刷起的你 | 給想要重新復習的面試老司機 | Python
- LC1 - Two Sum
C語言 Sol:LeetCode 1.兩數之和 Two Sum (C語言)
這個作者的答案真的好C好難但感覺超厲害,另外因為他的Leetcode可能是比較舊的,所以他input的參數沒有 int* returnSize ,必須要在有答案的時候* returnSize = 2;找不到答案的時候* returnSize = 0。
- LC121 - Best Time to Buy and Sell Stock
C語言 Sol:C program for Best time to buy and Sell stock
- LC242 - Valid Anagram
C語言 Sol:Pure C||Hash table
這個寫法很簡潔,先排除掉長度不一的字串,再用array來記錄字母出現的次數,但缺點是沒辦法處理follow up。
Follow up: What if the inputs contain Unicode characters? How would you adapt your solution to such a case?
Github 找到參考回答 eMahtab ,改用hash table來記錄。
Answer : Use a hash table instead of a fixed size counter. Imagine allocating a large size array to fit the entire range of unicode characters, which could go up to more than 1 million. A hash table is a more generic solution and could adapt to any range of characters.
- LC20 - Valid Parentheses
C語言 Sol:C using stack
