judge route circle

Judge Route Circle

nitially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.
The move sequence is represented by a string. And each move is represent by a character. The valid robot moves are R (Right), L (Left), U (Up) and D (down). The output should be true or false representing whether the robot makes a circle.
Example 1:
Input:’UD’
Output:’true’
Example 2:
Input:’LL’
Output:’false’

method 1

1
2
3
4
5
s=['U','U','R','D','D','L']
if s.count('U') == s.count('D') and s.count('R') == s.count('L'):
print('true')
else:
print('false')

method

1
2
3
4
5
6
7
8
9
10
11
s=['U','U','R','D','D','L']
x=y=0
for foot in s:
if foot=='U': y+=1
elif foot=='D': y+=-1
elif foot=='R': x+=1
elif foot=='L': x+=-1
if x==y==0:
print('ture')
else:
print('false')