I am a little confused about the restriction of this question.
We are not allowed to use extra space in this question, does it mean we can not declare any variables except for x?
Nah, that's just bad wording. Even the corresponding article uses some extra space/variables. What they mean is that you shouldn't use a vector or string or so. Try doing it with just some int variable(s).
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.