-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlongestSubstring.cpp
More file actions
49 lines (45 loc) · 994 Bytes
/
longestSubstring.cpp
File metadata and controls
49 lines (45 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
int main()
{
string word;
cout << "Enter the String : ";
cin >> word;
vector<string> ans;
int n = word.size();
for (int i = 0; i < n; i++)
{
for (int j = i; j < n; j++)
{
string sub = word.substr(i, j + 1);
ans.push_back(sub);
}
}
for (int i = 0; i < ans.size(); i++)
{
cout << ans[i] << " ";
}
int flag=0;
for (int i = 0; i < ans.size(); i++)
{
string sub = ans[i];
for (int j = 0; j < ans[i].size(); j++)
{ flag =0;
for (int k = j + 1; k < ans[i].size(); k++)
{
if (sub[j] == sub[k])
{
flag = 1;
break;
}
}
}
if (flag == 0)
{
cout << sub.size() << " ";
}
}
}