Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

largest substring with no repetition #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions largest substring/largestSubstring.cpp
@@ -0,0 +1,50 @@
// largestSubstring.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <sstream>
#include<iostream>
#include<cstring>
using namespace std;

// find the largest substring
string find_largest_Substring(string s){

string largeString,tempString;
tempString=s[0];
int pos;
for (unsigned int i=1;i<s.length();i++)
{
//check if the character is unique
pos=tempString.find(s[i]);
if (pos>=0 )
{
if (largeString.length()<tempString.length())
{
largeString=tempString;
}
tempString =tempString .substr (pos+1,tempString .length() );
}
tempString +=s[i];
}
if (tempString.length()==s.length () || tempString.length()>largeString.length())
{
return tempString;
}
else{
return largeString ;
}
}

int _tmain(int argc, _TCHAR* argv[])
{
string s;
s="parma pizzav";
cout <<"the string is '"<<s<< "' the largest substring is '"<< find_largest_Substring(s)<<"'"<<endl;
s="abcdefg hijk lmnopqrstuvwxyzadgc";
cout <<"the string is '"<<s<< "' the largest substring is '"<< find_largest_Substring(s)<<"'"<<endl;
s="abcdefg hijklmnopqrstuvwxyz";
cout <<"the string is '"<<s<< "' the largest substring is '"<< find_largest_Substring(s)<<"'"<<endl;
return 0;
}