Skip to content

Jewels and stones #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
17 changes: 17 additions & 0 deletions solution/0760.Find Anagram Mappings/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.*;

class Solution {
public int[] anagramMappings(int[] A, int[] B) {
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
Map<Integer, Integer> map = new HashMap<>();

for (int i = 0; i < B.length; i++) {
map.put(B[i], i);
}
int[] res = new int[B.length];
int j = 0;
for (int k : A) {
res[j++] = map.get(k);
}

return res;
}
}
18 changes: 18 additions & 0 deletions solution/0771.Jewels and Stones/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public int numJewelsInStones(String J, String S) {
int res = 0;
for (char c : S.toCharArray()) {
if (contains(J, c))
res++;
}
return res;
}

public boolean contains(String s, char c) {
for (char k : s.toCharArray()) {
if (k == c)
return true;
}
return false;
}
}