Help : why I pass 32/34


  • 0
    G

    Here is my code:

    class Solution(object):
        def nextGreaterElement(self, n):
            """
            :type n: int
            :rtype: int
            """
            work,index=[ele for ele in str(n)],-1
            for i in range(len(work)-1,0,-1):
                if int(work[i-1])<int(work[i]):
                    index=i-1
                    break
            else:
                return -1
            key=index
            for i in range(len(work)-1,index,-1):
                if int(work[i])>int(work[index]):
                    key=i
                    break
            #print(work)
            #print("%d %d" %(index,key))
            
            return int(''.join(work[:index]+[work[key]]+sorted(work[index:key]+work[key+1:])))
                    
    
    
    

    But I got the information below:

    0_1504839124473_屏幕快照 2017-09-08 上午10.50.45.png

    Can anyone help?


  • 0
    S

    same problem here. Don't understand. This should be the right answer right?


  • 2
    N

    The maximum value possible for 32-bit integer is "2,147,483,647". Your answer exceeds that. So, the expected answer is -1.


Log in to reply
 

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