在LeetCode刷题应尽量避免使用全局变量 Posted on 2021-06-06 Edited on 2023-07-04 In 指尖飞舞 , 算法 , LeetCode 摘要:会导致奇怪问题。 力扣的判题机在读取您的代码后,对每个测试用例,都会初始化一次类,但全局变量和类内静态变量需要您手动初始化。但有时候即便手动初始化依然出错,所以应当尽量将变量初始化在类中。但是,有时候初始化超大数组又不得不在堆上创建,所以这种事情还得根据实际情况自己权衡一下。 相关链接: 某些测试用例下,执行代码返回结果正确,但提交解答却出错了 Post author: zxy Post link: https://ntifs.com/2021/06/06/在LeetCode刷题应尽量避免使用全局变量/ Copyright Notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.