Calculate the number of each completely opposite moves


  • 0
    P

    Simple fundamental is to check if the robot moves in one direction once, does it goes opposite once too or not. If the count of steps in any one direction is not equal to the count in another direction then the robot doesn't makes a circle.
    Code for python 3:

    move={'U':0,'D':0,'R':0,'L':0}
            for i in moves:
                if i not in move:
                    move[i]=1
                else:
                    move[i]+=1
            if move['U']==move['D'] and move['R']==move['L']:
                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.