Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 30aab02

Browse files
Merge pull request doocs#214 from furahadamien/jewelsAndStones
Jewels and stones
2 parents 4f173a7 + 7ac6f06 commit 30aab02

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

‎solution/0760.Find Anagram Mappings/README.md‎

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int[] anagramMappings(int[] A, int[] B) {
5+
Map<Integer, Integer> map = new HashMap<>();
6+
for (int i = 0; i < B.length; i++) {
7+
map.put(B[i], i);
8+
}
9+
int[] res = new int[B.length];
10+
int j = 0;
11+
for (int k : A) {
12+
res[j++] = map.get(k);
13+
}
14+
return res;
15+
}
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int numJewelsInStones(String J, String S) {
3+
int res = 0;
4+
for (char c : S.toCharArray()) {
5+
if (contains(J, c))
6+
res++;
7+
}
8+
return res;
9+
}
10+
11+
public boolean contains(String s, char c) {
12+
for (char k : s.toCharArray()) {
13+
if (k == c)
14+
return true;
15+
}
16+
return false;
17+
}
18+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /