leetcode解题

This commit is contained in:
wu xiangkai
2025-10-22 16:35:11 +08:00
parent 75c4bd8473
commit 7bbd47f65f
3 changed files with 107 additions and 0 deletions

26
136.single-number.java Normal file
View File

@@ -0,0 +1,26 @@
/*
* @lc app=leetcode id=136 lang=java
*
* [136] Single Number
*/
// @lc code=start
class Solution {
/**
* 可以通过对数组中所有整数进行异或来找出该数,
* 因为对于出现两次的整数异或之后都为0
* 而对于只出现过一次的整数和0异或之后为其本身
*
* @param nums
* @return
*/
public int singleNumber(int[] nums) {
int r = 0;
for(int i = 0; i < nums.length; i++) {
r = r ^ nums[i];
}
return r;
}
}
// @lc code=end