There was an error while loading. Please reload this page.
1 parent c068161 commit c107334Copy full SHA for c107334
String/1698.Number-of-Distinct-Substrings-in-a-String/1698.Number-of-Distinct-Substrings-in-a-String_v1.cpp
@@ -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