Skip to content

Commit c107334

Browse files
authored
Create 1698.Number-of-Distinct-Substrings-in-a-String_v1.cpp
1 parent c068161 commit c107334

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
class TrieNode
3+
{
4+
public:
5+
TrieNode* next[26];
6+
};
7+
public:
8+
int countDistinct(string s)
9+
{
10+
TrieNode* root = new TrieNode();
11+
int count = 0;
12+
for (int i=0; i<s.size(); i++)
13+
{
14+
TrieNode* node = root;
15+
for (int j=i; j<s.size(); j++)
16+
{
17+
if (node->next[s[j]-'a']==NULL)
18+
{
19+
node->next[s[j]-'a'] = new TrieNode();
20+
count ++;
21+
}
22+
node = node->next[s[j]-'a'];
23+
}
24+
}
25+
return count;
26+
}
27+
};

0 commit comments

Comments
 (0)