Number of Good Ways to Split a String LeetCode solution in Python

1
class Solution:
2
def numSplits(self, s: str) -> int:
3
one = set()
4
two = set()
5
dic = {}
6

7
for i in s:
8
dic[i] = dic.get(i, 0) + 1
9
two.add(i)
10
tot = 0
11

12
for i in s:
13
one.add(i)
14
dic[i] -= 1
15
if dic[i] == 0:
16
two.remove(i)
17

18
if len(one) == len(two):
19
tot += 1
20
return tot

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0