作者Yuan0124 (YC)
看板C_and_CPP
标题[问题] LeetCode global and static 问题
时间Fri Sep 15 09:13:55 2017
开发平台(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://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1505438038.A.ADD.html
1F:推 steve1012: 你贴过去的是那些? 附个 screen shot 吧 09/15 09:23
2F:→ steve1012: 好std sort 不用吗 09/15 09:23
4F:→ Yuan0124: 小弟想要练习一下快速排序法而已XD 09/15 09:31
5F:推 outofyou: 有看过存取记忆体超过范围导致这种情形的案例。 09/15 09:47
6F:推 steve1012: 我是指你是直接这段code 全贴吗 09/15 12:12
7F:→ Yuan0124: 是的,除了main没贴以外其他都贴了上去 09/16 02:54