관리 메뉴

솜씨좋은장씨

[leetCode] 434. Number of Segments in a String (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 434. Number of Segments in a String (Python)

솜씨좋은장씨 2020. 8. 2. 23:31
728x90
반응형

Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.

Please note that the string does not contain any non-printable characters.

 

Example:

Input: "Hello, my name is John"
Output: 5

Solution

class Solution:
    def countSegments(self, s: str) -> int:
        answer = len(s.split())
        return answer

 

 

SOMJANG/CODINGTEST_PRACTICE

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

 

Comments