657. Robot Return to Origin Easy

@problem@discussion
#String#Simulation



1/**
2 * [657] Robot Return to Origin
3 *
4 * There is a robot starting at the position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves.
5 * You are given a string moves that represents the move sequence of the robot where moves[i] represents its i^th move. Valid moves are 'R' (right), 'L' (left), 'U' (up), and 'D' (down).
6 * Return true if the robot returns to the origin after it finishes all of its moves, or false otherwise.
7 * Note: The way that the robot is "facing" is irrelevant. 'R' will always make the robot move to the right once, 'L' will always make it move left, etc. Also, assume that the magnitude of the robot's movement is the same for each move.
8 *  
9 * Example 1:
10 * 
11 * Input: moves = "UD"
12 * Output: true
13 * Explanation: The robot moves up once, and then down once. All moves have the same magnitude, so it ended up at the origin where it started. Therefore, we return true.
14 * 
15 * Example 2:
16 * 
17 * Input: moves = "LL"
18 * Output: false
19 * Explanation: The robot moves left twice. It ends up two "moves" to the left of the origin. We return false because it is not at the origin at the end of its moves.
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	1 <= moves.length <= 2 * 10^4
25 * 	moves only contains the characters 'U', 'D', 'L' and 'R'.
26 * 
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/robot-return-to-origin/
31// discuss: https://leetcode.com/problems/robot-return-to-origin/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36    pub fn judge_circle(moves: String) -> bool {
37        false
38    }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_657() {
49    }
50}
51


Back
© 2025 bowen.ge All Rights Reserved.