434. Number of Segments in a String Easy
1/**
2 * [434] Number of Segments in a String
3 *
4 * Given a string s, return the number of segments in the string.
5 * A segment is defined to be a contiguous sequence of non-space characters.
6 *
7 * Example 1:
8 *
9 * Input: s = "Hello, my name is John"
10 * Output: 5
11 * Explanation: The five segments are ["Hello,", "my", "name", "is", "John"]
12 *
13 * Example 2:
14 *
15 * Input: s = "Hello"
16 * Output: 1
17 *
18 *
19 * Constraints:
20 *
21 * 0 <= s.length <= 300
22 * s consists of lowercase and uppercase English letters, digits, or one of the following characters "!@#$%^&*()_+-=',.:".
23 * The only space character in s is ' '.
24 *
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/number-of-segments-in-a-string/
29// discuss: https://leetcode.com/problems/number-of-segments-in-a-string/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34 pub fn count_segments(s: String) -> i32 {
35 0
36 }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_434() {
47 }
48}
49
Back
© 2025 bowen.ge All Rights Reserved.