代码拉取完成,页面将自动刷新
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
public class Test {
int[] nums;
String jewels = "aA";
String stones = "aAAbbbb";
class Node {
int val;
Node next;
Node random;
public Node(int val) {
this.val = val;
this.next = null;
this.random = null;
}
}
public int singleNumber(int[] nums) {
HashSet<Integer> set = new HashSet<>();
for (int i = 0; i < nums.length; i++) {
if (!set.contains(nums[i])) {
set.add(nums[i]);
}else {
set.remove(nums[i]);
}
}
for (int i = 0; i < nums.length; i++) {
if (set.contains(nums[i])) {
return nums[i];
}
}
return -1;
}
public int numJewelsInStones(String jewels, String stones) {
int count = 0;
HashSet<Character> set = new HashSet<>();
char[] arrayOfJewels = jewels.toCharArray();
char[] arrayOfStones = stones.toCharArray();
for (int i = 0; i < arrayOfJewels.length; i++) {
set.add(arrayOfJewels[i]);
}
for (int i = 0; i < arrayOfStones.length; i++) {
if (set.contains(arrayOfStones[i])) {
count++;
}
}
return count;
}
public Node copyRandomList(Node head) {
Map<Node,Node> map = new HashMap<>();
Node cur = head;
while (cur != null) {
Node newNode = new Node(cur.val);
map.put(cur,newNode);
cur = cur.next;
}
cur = head;
while (cur != null) {
map.get(cur).next = map.get(cur.next);
map.get(cur).random = map.get(cur.random);
cur = cur.next;
}
return map.get(head);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。