Why I got wrong result by using static variabls, but fine with class member variables?

  • 0

    The algorithm is the same idea with leetcode.
    I use a little different ways to implement.
    One I use class member variables to store" offset, bufsize, buffer[]" status. everything works fine.
    The other one is to make them static variables. it stops working. got wrong result.
    I don't quite understand why...

  • 1

    Hi @mmangelmm,

    This is actually not your code's fault and is due to a limitation of OJ. As OJ runs all test cases in one go, the static variables preserved its previous states and caused issues. Please read the FAQ, especially the question "Why does my code produce a different output compared to my local environment?".

    Therefore you should use class member variables for solving this question.

  • 0
    This post is deleted!

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.