836. rectangles overlap
class Solution {
public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
if(rec2[1] >= rec1[3] || rec1[1] >= rec2[3]){
return false;
}
if(rec1[0] >= rec2[2] || rec1[2] <= rec2[0]){
return false;
}
return true;
}
}
class Solution {
public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
return (Math.min(rec1[2], rec2[2]) > Math.max(rec1[0], rec2[0]) &&
Math.min(rec1[3], rec2[3]) > Math.max(rec1[1], rec2[1]));
}
}
17. The print face questions from 1 to the maximum number of bits n
class Solution {
public int[] printNumbers(int n) {
int x = (int)Math.pow(10,n);
int[] res = new int[x-1];
for(int i=0;i<x-1;i++){
res[i] = i+1;
}
return res;
}
}
class Solution {
public int[] printNumbers(int n) {
String num ="";
for(int i = 0 ; i <= n ;i++) {
if(i == 0)
num += "1";
else
num += "0";
}
int index = Integer.valueOf(num);
int []reuslt = new int[--index];
for(int i = 0 ; i < index ;i++) {
reuslt[i] = i+1;
}
return reuslt;
}
}
class Solution {
public int[] printNumbers(int n) {
//因为n为正整数,所以最小为10,也可以把10改为9,100改为99等
int[] map = { 10, 100, 1000, 10_000, 100_000, 1_000_000, 10_000_000,
100_000_000, 1_000_000_000, Integer.MAX_VALUE };
int size = map[n-1];
int[] ans = new int[size - 1];
for (int i = 1; i < size; i++) {
ans[i - 1] = i;
}
return ans;
}
}
class Solution {
public int[] printNumbers(int n) {
int temp = 1;
for(int i=0;i<n;i++){
temp *= 10;
}
int[] rec = new int[temp-1];
int index=0;
for(int k=1;k<temp;k++){
rec[index] = k;
index++;
}
return rec;
}
}
Interview questions 56 - II digital frequency array appears II.
class Solution {
public int singleNumber(int[] nums) {
Arrays.sort(nums);
for(int i=0;i<nums.length-2;i++){
if(nums[i]==nums[i+1]&&nums[i+1]==nums[i+2]){
i +=2;
}else{
return nums[i];
}
}
return nums[nums.length-1];
}
}
//还没搞懂...
class Solution {
public int singleNumber(int[] nums) {
int a = 0;
int b = 0;
for(int num : nums) {
a = (a ^ num) & ~b;
b = (b ^ num) & ~a;
}
return a;
}
}
class Solution {
public int singleNumber(int[] nums) {
int ans = 0;
//int 32位
for(int i=0;i<32;i++){
int count =0;
for(int num:nums){
if((num&(1<<i))!=0) count++;
}
if(count%3!=0) ans += 1<<i;
}
return ans;
}
}
class Solution {
public int singleNumber(int[] nums) {
Map<Integer,Integer> map=new HashMap<Integer,Integer>();
for(int num:nums) {
map.put(num, map.getOrDefault(num, 0)+1);
}
for(Object key:map.keySet()) {
if(map.get(key).equals(1)) return (int) key;
}
return 0;
}
}
The more you know, the more you do not know.
Proper way without surgery, patients can still seek, there is no way to surgery, ending surgery.
If you have other questions, welcome message, we can discuss, learn together and progress together