File tree Expand file tree Collapse file tree 1 file changed +70
-0
lines changed
Expand file tree Collapse file tree 1 file changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * @lc app=leetcode.cn id=136 lang=golang
3+ *
4+ * [136] 只出现一次的数字
5+ *
6+ * https://leetcode.cn/problems/single-number/description/
7+ *
8+ * algorithms
9+ * Easy (72.27%)
10+ * Likes: 2740
11+ * Dislikes: 0
12+ * Total Accepted: 846.2K
13+ * Total Submissions: 1.2M
14+ * Testcase Example: '[2,2,1]'
15+ *
16+ * 给你一个 非空 整数数组 nums ,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。
17+ *
18+ * 你必须设计并实现线性时间复杂度的算法来解决此问题,且该算法只使用常量额外空间。
19+ *
20+ *
21+ *
22+ *
23+ *
24+ * 示例 1 :
25+ *
26+ *
27+ * 输入:nums = [2,2,1]
28+ * 输出:1
29+ *
30+ *
31+ * 示例 2 :
32+ *
33+ *
34+ * 输入:nums = [4,1,2,1,2]
35+ * 输出:4
36+ *
37+ *
38+ * 示例 3 :
39+ *
40+ *
41+ * 输入:nums = [1]
42+ * 输出:1
43+ *
44+ *
45+ *
46+ *
47+ * 提示:
48+ *
49+ *
50+ * 1 <= nums.length <= 3 * 10^4
51+ * -3 * 10^4 <= nums[i] <= 3 * 10^4
52+ * 除了某个元素只出现一次以外,其余每个元素均出现两次。
53+ *
54+ *
55+ *
56+ *
57+ */
58+
59+ package jzoffer
60+
61+ // @lc code=start
62+ func singleNumber (nums []int ) int {
63+ single := 0
64+ for _ , num := range nums {
65+ single ^= num
66+ }
67+ return single
68+ }
69+
70+ // @lc code=end
You can’t perform that action at this time.
0 commit comments