Home  >  Q&A  >  body text

c++ - 请问一下为什么leetcode上那个只有一个class类?

用c++刷题,发现只有一个class类。是leetcode自己有main函数哪些吗?然后是直接调用这个类,去测试运行的吗?如果我要用一个全局变量怎么办哦?第一次上leetcode,不太明白,,,

ringa_leeringa_lee2764 days ago1133

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 13:58:36

    It is best not to define global or static variables outside the class. This will affect your test results, because the test cases all use this piece of code. (Probably it just included this class file).

    The correct approach is to add member variables to the class and initialize them in the default constructor.

    For other related questions, please see the official FAQ.

    https://leetcode.com/faq/

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 13:58:36

    leetcode requires you to write a function to complete the specified requirements, and the others have already been written. Not all codes have to be written by yourself

    reply
    0
  • Cancelreply