Why this solution is AC? An object does not cost extra space?


  • 0
    S
    public class Solution {
        public boolean isPalindrome(int x) {
            StringBuilder sb1=new StringBuilder(Integer.toString(x));//  extra space??
            StringBuilder sb2=new StringBuilder(Integer.toString(x));//  extra space??
            return sb1.toString().equals(sb2.reverse().toString());
        }
    }
    

    Or does for(int i=0;i<len;i++) cost exra space?


  • 0
    G

    Just a guess, but strings are probably implemented as dynamic arrays since you can append infinitely to them.


  • 0
    I

    Well it most definitely does use extra space but they can't (or at least they don't) test it in the OJ


Log in to reply
 

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