FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode-algorithms/src/ReorderDataInLogFiles.java at master · anishLearnsToCode/leetcode-algorithms · GitHub
anishLearnsToCode
/
leetcode-algorithms
Public
Notifications
You must be signed in to change notification settings
Fork
17
Star
98
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode-algorithms
/
src
/
ReorderDataInLogFiles.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (29 loc) · 1.1 KB
Breadcrumbs
leetcode-algorithms
/
src
/
ReorderDataInLogFiles.java
Copy path
File metadata and controls
33 lines (29 loc) · 1.1 KB
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
33
import
java
.
util
.
Arrays
;
public
class
ReorderDataInLogFiles
{
public
String
[]
reorderLogFiles
(
String
[]
logs
) {
Arrays
.
sort
(
logs
, (
log1
,
log2
) -> {
String
[]
split1
=
log1
.
split
(
" "
,
2
);
String
[]
split2
=
log2
.
split
(
" "
,
2
);
boolean
isDigit1
=
Character
.
isDigit
(
split1
[
1
].
charAt
(
0
));
boolean
isDigit2
=
Character
.
isDigit
(
split2
[
1
].
charAt
(
0
));
// case 1). both logs are letter-logs
if
(!
isDigit1
&& !
isDigit2
) {
// first compare the content
int
cmp
=
split1
[
1
].
compareTo
(
split2
[
1
]);
if
(
cmp
!=
0
)
return
cmp
;
// logs of same content, compare the identifiers
return
split1
[
0
].
compareTo
(
split2
[
0
]);
}
// case 2). one of logs is digit-log
if
(!
isDigit1
)
// the letter-log comes before digit-logs
return
-
1
;
else
if
(!
isDigit2
)
return
1
;
else
// case 3). both logs are digit-log
return
0
;
});
return
logs
;
}
}
Back
|
FazBrowse Home
|
New Git URL