Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve Problem 2490. Circular Sentence #1615

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ LeetSpace serves as a dedicated workspace and archive for my [LeetCode](https://
| [2485. Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer/) | Easy | [C](./old-problems/2485/c/solution.c) [C++](./old-problems/2485/solution.cpp) |
| [2486. Append Characters to String to Make Subsequence](https://leetcode.com/problems/append-characters-to-string-to-make-subsequence/) | Medium | [C](./old-problems/2486/c/solution.c) [C++](./old-problems/2486/solution.cpp) |
| [2487. Remove Nodes From Linked List](https://leetcode.com/problems/remove-nodes-from-linked-list/) | Medium | [C++](./old-problems/2487/solution.cpp) |
| [2490. Circular Sentence](https://leetcode.com/problems/circular-sentence/) | Easy | [C++](./old-problems/2490/solution.cpp) |
| [2497. Maximum Star Sum of a Graph](https://leetcode.com/problems/maximum-star-sum-of-a-graph/) | Medium | [C++](./old-problems/2497/solution.cpp) |
| [2511. Maximum Enemy Forts That Can Be Captured](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | [C](./old-problems/2511/c/solution.c) [C++](./old-problems/2511/solution.cpp) |
| [2525. Categorize Box According to Criteria](https://leetcode.com/problems/categorize-box-according-to-criteria/) | Easy | [C](./old-problems/2525/c/solution.c) [C++](./old-problems/2525/solution.cpp) |
Expand Down
2 changes: 2 additions & 0 deletions old-problems/2490/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
get_dir_name(id)
add_problem_test(test-${id} test.yaml)
14 changes: 14 additions & 0 deletions old-problems/2490/solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <string>

class Solution {
public:
bool isCircularSentence(std::string sentence) {
if (sentence.front() != sentence.back()) return false;
for (int i = sentence.size() - 2; i > 0; --i) {
if (sentence[i] == ' ' && sentence[i - 1] != sentence[i + 1]) {
return false;
}
}
return true;
}
};
26 changes: 26 additions & 0 deletions old-problems/2490/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: 2490. Circular Sentence

types:
inputs:
sentence: std::string
output: bool

solutions:
cpp:
function: isCircularSentence

test_cases:
example_1:
inputs:
sentence: leetcode exercises sound delightful
output: true

example_2:
inputs:
sentence: eetcode
output: true

example_3:
inputs:
sentence: Leetcode is cool
output: false