更新了第202,242,349题

This commit is contained in:
zqh1059405318
2021-05-13 11:31:02 +08:00
parent f56d49a94f
commit 1613d2b4b0
3 changed files with 59 additions and 13 deletions

View File

@ -84,7 +84,28 @@ public:
Java
```java
class Solution {
public boolean isHappy(int n) {
Set<Integer> record = new HashSet<>();
while (n != 1 && !record.contains(n)) {
record.add(n);
n = getNextNumber(n);
}
return n == 1;
}
private int getNextNumber(int n) {
int res = 0;
while (n > 0) {
int temp = n % 10;
res += temp * temp;
n = n / 10;
}
return res;
}
}
```
Python

View File

@ -86,6 +86,7 @@ public:
Java
```java
class Solution {
public boolean isAnagram(String s, String t) {
int[] record = new int[26];
for (char c : s.toCharArray()) {
@ -101,7 +102,7 @@ public boolean isAnagram(String s, String t) {
}
return true;
}
}
```
Python

View File

@ -75,7 +75,31 @@ public:
Java
```java
class Solution {
public int[] intersection(int[] nums1, int[] nums2) {
Set<Integer> record = new HashSet<Integer>();
Set<Integer> unique = new HashSet<Integer>();
for (int num : nums1) {
record.add(num);
}
for (int num : nums2) {
if (record.contains(num)) {
unique.add(num);
}
}
int[] res = new int[unique.size()];
int index = 0;
for (int num : unique) {
res[index++] = num;
}
return res;
}
}
```
Python