LeetCodeTop100

Picasun Lv4

哎呀 我怎么在刷算法 刷吧

Easy

Day1:两数之和

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public int[] twoSum(int[] nums, int target) {
int length=nums.length;//length function
for(int i=0;i<length;i++){
for(int j=i+1;j<length;j++){
if(nums[i]+nums[j]==target){
return new int[]{i,j};//new a array to return
}
}
}
return new int[]{}; //must have return
}
}

只出现一次的数字

1
2
3
4
5
6
7
8
9
class Solution {
public int singleNumber(int[] nums) {
int ans=0;
for(int i=0;i<nums.length;i++){
ans ^=nums[i];//like += -+ XOR 0:same 1:diff
}
return ans;
}
}

Medium

Hard

  • Title: LeetCodeTop100
  • Author: Picasun
  • Created at : 2025-04-21 22:26:46
  • Updated at : 2026-10-09 09:28:25
  • Link: https://picasun.github.io/2025/04/21/LeetCodeTop100/
  • License: This work is licensed under CC BY-NC-SA 4.0.