FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/longestsubstring.java at master · wpande/leetcode · GitHub
wpande
leetcode
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
longestsubstring.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (32 loc) · 867 Bytes
Breadcrumbs
leetcode
/
longestsubstring.java
Copy path
File metadata and controls
32 lines (32 loc) · 867 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
public
class
Solution
{
public
int
lengthOfLongestSubstring
(
String
s
) {
HashMap
<
Character
,
Integer
>
hm
=
new
HashMap
<
Character
,
Integer
>();
int
len
=
s
.
length
();
if
(
len
==
0
)
return
0
;
int
i
,
j
;
i
=
0
;
j
=
0
;
int
max
=
1
;
hm
.
put
(
s
.
charAt
(
j
),
0
);
while
(
j
<
len
){
if
(
j
==
len
-
1
){
if
(
j
-
i
+
1
>
max
)
max
=
j
-
i
+
1
;
return
max
;
}
j
=
j
+
1
;
if
(
hm
.
containsKey
(
s
.
charAt
(
j
))){
if
(
j
-
i
>
max
){
max
=
j
-
i
;
}
int
newi
=
hm
.
get
(
s
.
charAt
(
j
))+
1
;
for
(
int
k
=
i
;
k
<
newi
;
k
++)
hm
.
remove
(
s
.
charAt
(
k
));
i
=
newi
;
}
hm
.
put
(
s
.
charAt
(
j
),
j
);
}
return
max
;
}
}
Back
|
FazBrowse Home
|
New Git URL