Python code


  • 0
    Z
    class Solution(object):
        def judgeCircle(self, moves):
            """
            :type moves: str
            :rtype: bool
            :Robot can return if there is equal number of L and R, U and D
            """
            lcnt=0
            rcnt=0
            ucnt=0
            dcnt=0
            if len(moves)==0:
                return True
            elif len(moves)==1:
                return False
            else:
                for i in range(len(moves)):
                    if moves[i]=='L':
                        lcnt+=1
                    elif moves[i]=='R':
                        rcnt+=1
                    elif moves[i]=='U':
                        ucnt+=1
                    elif moves[i]=='D':
                        dcnt+=1
                print lcnt, rcnt, ucnt,dcnt
                if lcnt==rcnt and ucnt==dcnt:
                    return True
                else:
                    return False
            
    

Log in to reply
 

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