[问题] LeetCode global and static 问题

楼主: Yuan0124 (YC)   2017-09-15 09:13:55
开发平台(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.
这段英文有看没有懂,有大大可以指教吗?
感谢指教
作者: steve1012 (steve)   2017-09-15 09:23:00
你贴过去的是那些? 附个 screen shot 吧好std sort 不用吗
楼主: Yuan0124 (YC)   2017-09-15 09:30:00
https://imgur.com/a/RmL9G小弟想要练习一下快速排序法而已XD
作者: outofyou   2017-09-15 09:47:00
有看过存取内存超过范围导致这种情形的案例。
作者: steve1012 (steve)   2017-09-15 12:12:00
我是指你是直接这段code 全贴吗
楼主: Yuan0124 (YC)   2017-09-16 02:54:00
是的,除了main没贴以外其他都贴了上去

Links booklink

Contact Us: admin [ a t ] ucptt.com