1. Description
Given a string s, return the number of segments in the string.
A segment is defined to be a contiguous sequence of non-space characters.
constraints :
- 0 <= s.length <= 300
- s consists of lowercase and uppercase English letters, digits, or one of the following characters "!@#$%^&*()_+-=',.:".
- The only space character in s is ' '.
2. Algorithms
- Start
- Split the string using split method and store into s agian.
- Return the length of s.
- End
3. Codes
class Solution:
def countSegments(self, s: str) -> int:
s = s.split()
return len(s)
4. Conclusion
'LeetCode > Easy' 카테고리의 다른 글
448 Find All Numbers Disappeared in an Array (0) | 2022.08.30 |
---|---|
441 Arranging Coins (0) | 2022.08.30 |
415 Add Strings (0) | 2022.08.30 |
414 Third Maximum Number (0) | 2022.08.30 |
412 Fizz Buzz (0) | 2022.08.29 |