We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ce3bd1d commit d4d903dCopy full SHA for d4d903d
leetcode/MEDIUM/Longest Substring Without Repeating Characters/Solution.java
@@ -0,0 +1,42 @@
1
+// Brute Force
2
+
3
+class Solution {
4
+ public int lengthOfLongestSubstring(String s) {
5
+ int len = s.length();
6
+ if(s == ""){
7
+ return 0;
8
+ }
9
10
+ int max_count = 0;
11
+ int count = 0;
12
13
+ Map map = new HashMap<Character,Integer>();
14
15
+ int i = 0;
16
+ int start = 0;
17
+ int tmp = 0;
18
+ while(i<len){
19
+ //System.out.println(map);
20
+ if(map.containsKey(s.charAt(i))){
21
+ if(count > max_count){
22
+ max_count = count;
23
24
+ i = start+1;
25
+ start++;
26
+ count = 0;
27
+ map.clear();
28
29
+ else{
30
+ map.put(s.charAt(i),tmp++);
31
+ count++;
32
+ i++;
33
34
35
36
37
38
39
40
+ return max_count;
41
42
+}
0 commit comments