commit 409f8f231fe19d4ba2fc459321b3a042aade320c
parent 6dd55f3f9a575cbba21cea088673999e733ed146
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Thu, 17 Oct 2024 14:51:00 +0200
1 Random Problem
Diffstat:
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/Problems/0434.cpp b/Problems/0434.cpp
@@ -0,0 +1,20 @@
+class Solution {
+ public:
+ int countSegments(const string &s) const {
+ const int n = size(s);
+ int res = 0;
+
+ for (int i = 0; i < n;) {
+ if (s[i] != ' ') {
+ while (i < n && s[i] != ' ')
+ i++;
+ res++;
+ } else {
+ while (i < n && s[i] == ' ')
+ i++;
+ }
+ }
+
+ return res;
+ }
+};
diff --git a/README.md b/README.md
@@ -333,6 +333,7 @@ for solving problems.
| 0430 | Medium | [Flatten a Multilevel Doubly Linked list](Problems/0430.cpp) |
| 0432 | Hard | [All O`one Data Structure](Problems/0432.cpp) |
| 0433 | Medium | [Minimum Genetic Mutation](Problems/0433.cpp) |
+| 0434 | Easy | [Number of Segments in a String](Problems/0434.cpp) |
| 0435 | Medium | [Non-overlapping Intervals](Problems/0435.cpp) |
| 0436 | Medium | [Find Right Interval](Problems/0436.cpp) |
| 0437 | Medium | [Path Sum III](Problems/0437.cpp) |