File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-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.com/problems/single-number/description/
7+ *
8+ * algorithms
9+ * Easy (63.24%)
10+ * Likes: 924
11+ * Dislikes: 0
12+ * Total Accepted: 121.3K
13+ * Total Submissions: 188.9K
14+ * Testcase Example: '[2,2,1]'
15+ *
16+ * 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。
17+ *
18+ * 说明:
19+ *
20+ * 你的算法应该具有线性时间复杂度。 你可以不使用额外空间来实现吗?
21+ *
22+ * 示例 1:
23+ *
24+ * 输入: [2,2,1]
25+ * 输出: 1
26+ *
27+ *
28+ * 示例 2:
29+ *
30+ * 输入: [4,1,2,1,2]
31+ * 输出: 4
32+ *
33+ */
34+
35+ // @lc code=start
36+ func singleNumber (nums []int ) int {
37+ ret := nums [0 ]
38+ for i := 1 ; i < len (nums ); i ++ {
39+ ret ^= nums [i ]
40+ }
41+ return ret
42+ }
43+ // @lc code=end
44+
You can’t perform that action at this time.
0 commit comments