Home Number of Segments in a String
Post
Cancel

Number of Segments in a String

Leetcode Problem

Number of Segments in a String

문자열 s가 주어졌을 때, 띄어쓰기를 기준으로 나뉘어진 문자열 조각의 개수를 구하는 문제입니다.

1
2
3
class Solution:
    def countSegments(self, s: str) -> int:
        return len(s.split())

split 함수를 통해 간단하게 조각의 개수를 구할 수 있었습니다.





참고

This post is licensed under CC BY 4.0 by the author.