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?


Log in to reply
 

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