- Java Solution:
- Runtime beats 72.84%
完成日期: 03/24/2018
关键词: 坐标
关键点: 出发点为 x = 0, y = 0
- class Solution
- {public boolean judgeCircle(String moves)
- {
- int x = 0;
- int y = 0;
- for(char c: moves.toCharArray())
- {
- switch(c)
- {
- case R:
- x++;
- break;
- case L:
- x--;
- break;
- case U:
- y++;
- break;
- case D:
- y--;
- break;
- default:
- System.out.println("Invalid move");
- }
- }
- return (x == 0 && y == 0);
- }
- }
参考资料: n/a
LeetCode 题目列表 - LeetCode Questions List
来源: http://www.bubuko.com/infodetail-2537882.html