FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Algorithm_LeetCode/src/string_handle/RansomNote_383.java at master · minuk8932/Algorithm_LeetCode · GitHub
minuk8932
/
Algorithm_LeetCode
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Algorithm_LeetCode
/
src
/
string_handle
/
RansomNote_383.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (32 loc) · 1.12 KB
Breadcrumbs
Algorithm_LeetCode
/
src
/
string_handle
/
RansomNote_383.java
Copy path
File metadata and controls
37 lines (32 loc) · 1.12 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
34
35
36
37
package
string_handle
;
/**
*
* @author minchoba
* LeetCode 383번 : Ransom Note
*
* @see https://www.leetcode.com/problems/ransom-note/description/
*
*/
public
class
RansomNote_383
{
public
boolean
canConstruct
(
String
ransomNote
,
String
magazine
) {
int
[]
alpha
=
new
int
[
26
];
int
lenR
=
ransomNote
.
length
();
int
lenM
=
magazine
.
length
();
boolean
[]
isVisited
=
new
boolean
[
26
];
for
(
int
i
=
0
;
i
<
lenR
;
i
++){
// Ransom note에 등장하는 단어를 각 알파 배열의 인덱스 별로 +1, 해당 인덱스를 방문한 것으로 처리
int
idx
=
ransomNote
.
charAt
(
i
) -
'a'
;
alpha
[
idx
]++;
isVisited
[
idx
] =
true
;
}
for
(
int
i
=
0
;
i
<
lenM
;
i
++){
// Magazine에 등장하는 단어를 각 알파 배열의 인덱스 별로 -1
alpha
[
magazine
.
charAt
(
i
) -
'a'
]--;
}
boolean
res
=
true
;
// 기본값 참
for
(
int
i
=
0
;
i
<
alpha
.
length
;
i
++){
// 0보다 큰 즉, magazine에 등장하지 않고 동시에, 방문 했던 인덱스의 경우
if
(
alpha
[
i
] >
0
&&
isVisited
[
i
]){
res
=
false
;
// 거짓
}
}
return
res
;
// 결과 반환
}
}
Back
|
FazBrowse Home
|
New Git URL