1 parent a1ef6b6 commit 82d7fd2Copy full SHA for 82d7fd2
3.Longest Substring Without Repeating Characters/Solution.java
@@ -0,0 +1,35 @@
1
+class Solution {
2
+ public int lengthOfLongestSubstring(String s) {
3
+ if(s==null || s.length()==0){
4
+ return 0;
5
+ }
6
+ if(s.length()==1){
7
+ return 1;
8
9
+
10
+ int left=0;
11
+ int right=0;
12
+ int ans=0;
13
14
+ HashSet<Character> set=new HashSet<>();
15
16
+ while(right<s.length()){
17
+ //to find the value of the particular index
18
+ char c = s.charAt(right);
19
20
+ //if the value exists in hashset or not
21
+ while(set.contains(c)){
22
+ set.remove(s.charAt(left));
23
+ left++;
24
25
+ set.add(c);
26
+ ans=Math.max(ans,right-left+1);
27
+ right++;
28
29
30
31
32
+ return ans;
33
34
35
+}
0 commit comments