Python not accepted,confused grammar


  • 0
    P
    class Solution:
        # @return a string
        def convertToTitle(self, num):
            ans = ""
            while num:
                ans = chr((num-1)%26)+"A" + ans;
                num = (num-1)/26;
                
            return ans;
    
    Input:	1
    Output:	"A"
    Expected:	"A"
    

    **

    • The Output and Expected are really confusing.Someone help.Thanks!

    **


  • 0
    S
    class Solution:
        # @return a string
        def convertToTitle(self, num):
            ans = ""
            while num:
                ans = chr((num-1)%26 + 65) + ans;
                num = (num-1)/26;
    
            return ans;
    

    I don't think ans = chr((num-1)%26)+"A" + ans is correct.


  • 0
    J

    change
    ans = chr(((num-1)%26)+ord('A'))+ans


Log in to reply
 

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