12345678910111213141516171819 |
- pub fn judge_circle(moves: String) -> bool {
- let mut x = 0;
- let mut y = 0;
- for m in moves.chars() {
- match m {
- 'U' => x = x + 1,
- 'D' => x = x - 1,
- 'L' => y = y + 1,
- 'R' => y = y - 1,
- _ => {},
- }
- }
- return y == 0 && x == 0;
- }
-
- pub fn main() {
- println!("Expected: true");
- println!("Got: {}", judge_circle("UDRULD".to_string()));
- }
|