--- tags: algorithms --- # [Leetcode] #1 Two Sum https://leetcode.com/problems/two-sum/ -- ## 遇到編譯問題 [source code](https://github.com/allenCheng1984/leetcode-notes/tree/master/1.%20Two%20Sum/c) 正常運作  要嘗試 refactor code, 在執行出錯  發現問題出在這行  為什麼單純宣告 int array 會出現 `segmentation fault`? 宣告 char array 卻沒影響?  --- ## ptt 版友的協助 ([link](https://www.ptt.cc/bbs/C_and_CPP/M.1672551970.A.87A.html)) 開啟 `-wAll` 把所有的 warning 秀出來,顯示第十行要初始化  -- but 補上去後,編譯過了,但執行反而出問題 ... Orz   -- ## 問題已解決 原來是只要傳入 function 裡的 argument pointer 都要用 malloc ... Orz [git commit](https://github.com/allenCheng1984/leetcode-notes/commit/dd339f787bd16ab956cb83fff8410314e5491ae4)  -- ## Final: 補上 Makefile 的編譯器參數、修正報出來的警告與 coding style fix https://github.com/allenCheng1984/leetcode-notes/commit/b7e6d37afe83f5ed09d928188d44dfb0c98451de
×
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