Number of Good Ways to Split a String (Leetcode 1525)
Problem Link: https://leetcode.com/problems/number-of-good-ways-to-split-a-string/
class Solution:
def numSplits(self, s: str) -> int:
d1={}
d2={}
for i in s:
if(i not in d1):
d1[i]=1
else:
d1[i]+=1
ans=0
for i in range(len(s)):
if(d1[s[i]]==1):
del d1[s[i]]
else:
d1[s[i]]-=1
if(s[i] not in d2):
d2[s[i]]=1
else:
d2[s[i]]+=1
if(len(d1)==len(d2)):
ans+=1
return ans
Previous*** Minimum Number of Moves to Make Palindrome (Leetcode 2193)NextDefanging an IP Address (Leetcode 1108)
Last updated