[問題] LeetCode global and static 問題

看板C_and_CPP作者 (YC)時間6年前 (2017/09/15 09:13), 編輯推噓3(304)
留言7則, 3人參與, 最新討論串1/1
開發平台(Platform): (Ex: Win10, Linux, ...) MacOS Sierra 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) XCode 問題(Question): Run code and submit solution 結果不同 餵入的資料(Input): [-1,0,1,0] 預期的正確結果(Expected Output): [[-1,0,1]] 錯誤結果(Wrong Output): [] 程式碼(Code):(請善用置底文網頁, 記得排版) http://codepad.org/tQbV4UCZ 補充說明(Supplement): LeetCode 15. 3Sum 放到LeetCode上run code 與 submit solution結果不同,點進問題解說中看到 First, please check if you are using any global or static variables. They are Evil, period. If you must declare one, reset them in the first line of your called method or in the default constructor. Why? Because the judger executes all test cases using the same program instance, global/static variables affect the program state from one test case to another. See this Discuss thread for more details. 這段英文有看沒有懂,有大大可以指教嗎? 感謝指教 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 108.189.66.69 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1505438038.A.ADD.html

09/15 09:23, , 1F
你貼過去的是那些? 附個 screen shot 吧
09/15 09:23, 1F

09/15 09:23, , 2F
好std sort 不用嗎
09/15 09:23, 2F

09/15 09:30, , 3F

09/15 09:31, , 4F
小弟想要練習一下快速排序法而已XD
09/15 09:31, 4F

09/15 09:47, , 5F
有看過存取記憶體超過範圍導致這種情形的案例。
09/15 09:47, 5F

09/15 12:12, , 6F
我是指你是直接這段code 全貼嗎
09/15 12:12, 6F

09/16 02:54, , 7F
是的,除了main沒貼以外其他都貼了上去
09/16 02:54, 7F
文章代碼(AID): #1PkobMhT (C_and_CPP)