Skip to content

Commit 7bd3a12

Browse files
committedMay 22, 2020
Adding Simple Solution - Problem - 434 - Number Segments String
1 parent 027fe9f commit 7bd3a12

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
 
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
##==================================
2+
## Leetcode
3+
## Student: Vandit Jyotindra Gajjar
4+
## Year: 2020
5+
## Problem: 434
6+
## Problem Name: Number of Segments in a String
7+
##===================================
8+
#
9+
#Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.
10+
#
11+
#Please note that the string does not contain any non-printable characters.
12+
#
13+
#Example:
14+
#
15+
#Input: "Hello, my name is John"
16+
#Output: 5
17+
class Solution:
18+
def countSegments(self, s):
19+
tmp = s.split() #Initialize tmp which is a list of the non-space characters
20+
return len(tmp) #We return the length of the list which whill be the number of segments

0 commit comments

Comments
 (0)
Please sign in to comment.