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...
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.