Skip to content

Commit 0933ca5

Browse files
committed
feat: add the solution of Judge Route Circle(657) with Java.
1 parent 0975816 commit 0933ca5

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
| [643][643-question] | [Maximum Average Subarray I][643-tips] | [][643-java] | [][643-js] | |
6666
| [645][645-question] | [Set Mismatch][645-tips] | [][645-java] | [][645-js] | |
6767
| [653][653-question] | [Two Sum IV - Input is a BST][653-tips] | [][653-java] | [][653-js] | |
68-
| [657][657-question] | [Judge Route Circle][657-tips] | | [][657-js] | |
68+
| [657][657-question] | [Judge Route Circle][657-tips] | [][657-java] | [][657-js] | |
6969
| [661][661-question] | [Image Smoother][661-tips] | | [][661-js] | |
7070
| [665][665-question] | [Non-decreasing Array][665-tips] | | [][665-js] | |
7171
| [669][669-question] | [Trim a Binary Search Tree][669-tips] | | [][669-js] | |
@@ -456,6 +456,7 @@
456456
[643-java]: ./src/_643/Solution.java
457457
[645-java]: ./src/_645/Solution.java
458458
[653-java]: ./src/_653/Solution.java
459+
[657-java]: ./src/_657/Solution.java
459460
[728-java]: ./src/_728/Solution.java
460461
[771-java]: ./src/_771/Solution.java
461462
[804-java]: ./src/_804/Solution.java

src/_657/Solution.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package _657;
2+
3+
class Solution {
4+
public boolean judgeCircle(String moves) {
5+
int[] count = new int[128];
6+
for (char c : moves.toCharArray()) {
7+
count[c]++;
8+
}
9+
return count['U'] == count['D'] && count['L'] == count['R'];
10+
}
11+
}

tips/657/README.md

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
1-
[xxxx][title]
1+
[Judge Route Circle][title]
22

33
## Description
4-
// 抄题目
54

5+
Initially, 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**.
66

7-
**Example:**
7+
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.
8+
9+
**Example 1:**
810

911
```
10-
// 抄Example
12+
Input: "UD"
13+
Output: true
1114
```
1215

13-
**Note:**
14-
// Note
15-
16-
**Tags:** // tags
17-
18-
19-
## 思路 1
20-
// 贴一些关键代码,说一些解题思路
21-
// (同一种语言可以写多种思路,与某种语言思路相同的另一种语言的思路无须赘述,但可以把代码贴在后面)
22-
```java
16+
**Example 2:**
2317

2418
```
25-
```javascript
26-
19+
Input: "LL"
20+
Output: false
2721
```
2822

29-
## 思路 2
30-
// 贴一些关键代码,说一些解题思路
31-
```java
32-
33-
```
23+
**Tags:** [String](https://leetcode.com/tag/string/)
3424

35-
## 思路 3
36-
// 贴一些关键代码,说一些解题思路
37-
```kotlin
25+
## 思路
26+
如题意,机器人会按照所给指令`U``D``L``R`进行上下左右移动。题目要求根据所给指令,计算机器人是否能走回原点。遍历指令数组,分别记录`U``D``L``R`的个数,若U=D且L=R则能走回远点。
3827

28+
```java
29+
class Solution {
30+
public boolean judgeCircle(String moves) {
31+
int[] count = new int[128];
32+
for (char c : moves.toCharArray()) {
33+
count[c]++;
34+
}
35+
return count['U'] == count['D'] && count['L'] == count['R'];
36+
}
37+
}
3938
```
4039

4140
## 结语
42-
41+
4342
如果你同我们一样热爱数据结构、算法、LeetCode,可以关注我们 GitHub 上的 LeetCode 题解:[LeetCode-Solution][ls]
4443

45-
[title]: https://leetcode.com/problems/xxxx
44+
[title]: https://leetcode.com/problems/judge-route-circle/description/
4645
[ls]: https://github.com/SDE603/LeetCode-Solution

0 commit comments

Comments
 (0)