• 문제 링크
Robot Return to Origin - LeetCode
Can you solve this real interview question? Robot Return to Origin - 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. You are giv
leetcode.com
• 풀이 코드
public class Solution {
public boolean judgeCircle(String moves) {
int y = 0, x = 0;
for (char c : moves.toCharArray()) {
switch (c) {
case 'U' -> y++;
case 'D' -> y--;
case 'L' -> x--;
case 'R' -> x++;
default -> {
}
}
}
return y == 0 && x == 0;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 671. Second Minimum Node In a Binary Tree - Java (0) | 2026.09.20 |
|---|---|
| [LeetCode] 661. Image Smoother - Java (0) | 2026.09.19 |
| [LeetCode] 653. Two Sum IV - Input is a BST - Java (0) | 2026.09.17 |
| [LeetCode] 645. Set Mismatch - Java (0) | 2026.09.16 |
| [LeetCode] 643. Maximum Average Subarray I - Java (0) | 2026.09.15 |
댓글