Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fc73fe6

Browse files
solves #2490: Circular Sentence in java
1 parent 1534755 commit fc73fe6

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@
784784
| 2475 | [Number of Unequal Triplets in Array](https://leetcode.com/problems/number-of-unequal-triplets-in-array) | [![Java](assets/java.png)](src/NumberOfUnequalTripletsInArray.java) | |
785785
| 2481 | [Minimum Cuts to Divide a Circle](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle) | [![Java](assets/java.png)](src/MinimumCutsToDivideACircle.java) | |
786786
| 2485 | [Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer) | [![Java](assets/java.png)](src/FindThePivotInteger.java) | |
787-
| 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | | |
787+
| 2490 | [Circular Sentence](https://leetcode.com/problems/circular-sentence) | [![Java](assets/java.png)](src/CircularSentence.java) | |
788788
| 2492 | [Minimum Score of a Path Between Two Cities](https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities) | [![Python](assets/python.png)](python/minimum_score_of_a_path_between_two_cities.py) | |
789789
| 2496 | [Maximum Value of a String in an Array](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array) | | |
790790
| 2500 | [Delete Greatest Value in Each Row](https://leetcode.com/problems/delete-greatest-value-in-each-row) | | |

‎src/CircularSentence.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://leetcode.com/problems/circular-sentence
2+
// T: O(N)
3+
// S: O(1)
4+
5+
public class CircularSentence {
6+
public boolean isCircularSentence(String sentence) {
7+
for (int index = 0 ; index < sentence.length() ; index++) {
8+
char letter = sentence.charAt(index);
9+
if (letter == ' ' && sentence.charAt(index - 1) != sentence.charAt(index + 1)) {
10+
return false;
11+
}
12+
}
13+
return sentence.charAt(0) == sentence.charAt(sentence.length() - 1);
14+
}
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /