Skip to content

Commit

Permalink
prob-2 cmpleted
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed May 5, 2020
1 parent 95130ac commit 4767617
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Problem-2 cmpleted.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

// TC: O(N^2)
// SC: O(N)

class Solution
{
public int lengthOfLongestSubstring(String s)
{
int ans = 0;
for(int i=0;i<s.length();i++)
{
HashSet<Character> set = new HashSet<>();
for(int j=i;j<s.length();j++)
{
if(set.contains(s.charAt(j)))
break;
else
{
set.add(s.charAt(j));
ans=Integer.max(ans,set.size());
}

}
}

return ans;
}
}
28 changes: 28 additions & 0 deletions Problem-2 cmpleted.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

// TC: O(N^2)
// SC: O(N)

class Solution
{
public int lengthOfLongestSubstring(String s)
{
int ans = 0;
for(int i=0;i<s.length();i++)
{
HashSet<Character> set = new HashSet<>();
for(int j=i;j<s.length();j++)
{
if(set.contains(s.charAt(j)))
break;
else
{
set.add(s.charAt(j));
ans=Integer.max(ans,set.size());
}

}
}

return ans;
}
}

0 comments on commit 4767617

Please sign in to comment.