---
# System prepended metadata

title: '[1525. Number of Good Ways to Split a String](https://leetcode.com/problems/number-of-good-ways-to-split-a-string/)'
tags: [leetcode]

---

---
tags: leetcode
---

# [1525. Number of Good Ways to Split a String](https://leetcode.com/problems/number-of-good-ways-to-split-a-string/)
---
# My Solution
## The Key Idea for Solving This Coding Question
## C++ Code
```cpp=
class Solution {
public:
    int numSplits(string s) {
        vector<int> leftSplit(s.size());
        unordered_set<char> leftSet;
        for (int i = 0; i < s.size(); ++i) {
            leftSet.insert(s[i]);
            leftSplit[i] = leftSet.size();
        }

        vector<int> rightSplit(s.size());
        unordered_set<char> rightSet;
        for (int i = s.size() - 1; i >= 0; --i) {
            rightSplit[i] = rightSet.size();
            rightSet.insert(s[i]);
        }

        int goodSplitCnt = 0;
        for (int i = 0; i + 1 < leftSplit.size(); ++i) {
            if (leftSplit[i] == rightSplit[i]) {
                ++goodSplitCnt;
            }
        }

        return goodSplitCnt;
    }
};
```
## Time Complexity
## Space Complexity
# Miscellane
<!--
# Test Cases
```
"aacaba"
```
```
"abcd"
```
```
"aaaaa"
```
```
"acbadbaada"
```
-->