Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
耐心看下我的思想演变过程吧,可能是大脑缺氧,用List装下标。
public int singleNumber(int[] nums) {
if (nums.length == 1)
return nums[0];
ArrayList<Integer> temp = new ArrayList<Integer>();

该博客讨论了LeetCode的136题,题目要求在出现两次的整数数组中找出唯一出现一次的数字。作者分享了从最初的超时解决方案到最终使用位运算的O(n)时间复杂度、O(1)空间复杂度的解决方案的过程,强调了位运算在解决此类问题中的高效性。
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



