-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path136. Single Number.html
More file actions
28 lines (27 loc) · 2.16 KB
/
Copy path136. Single Number.html
File metadata and controls
28 lines (27 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<html>
<head>
<title>136. Single Number</title>
<basefont face="Tahoma" size="2" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="exporter-version" content="Evernote Windows/304720 (en-US, DDL); Windows/10.0.14393 (Win64);"/>
<style>
body, td {
font-family: Tahoma;
font-size: 12pt;
}
</style>
</head>
<body>
<a name="5303"/>
<h1>136. Single Number</h1>
<div>
<table bgcolor="#D4DDE5" border="0">
<tr><td><b>Created:</b></td><td><i>5/29/2016 4:08 AM</i></td></tr>
<tr><td><b>Updated:</b></td><td><i>6/25/2016 4:12 AM</i></td></tr>
<tr><td><b>Tags:</b></td><td><i>##, Bit Manipulation, leetcode tag, Medium</i></td></tr>
</table>
</div>
<br/>
<div>
<span><div><a href="https://leetcode.com/problems/single-number/">https://leetcode.com/problems/single-number/</a></div><div><a href="http://www.lintcode.com/en/problem/single-number/">http://www.lintcode.com/en/problem/single-number/</a></div><div><br/></div><div>思路:</div><div>把所有数异或</div><div><a href="evernote:///view/712178/s5/0b191958-8e2c-4988-bfa4-537ca368c04a/0b191958-8e2c-4988-bfa4-537ca368c04a/" style="color:#69aa35">异或 xor</a></div><div><br/></div><div><span style="color: rgb(51, 51, 51);">只要是偶数次,都可以用这个方法</span></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.148438);"><div>public class Solution {</div><div> public int singleNumber(int[] A) {</div><div> if (A.length == 0 ) {</div><div> return 0;</div><div> }</div><div> int result = A[0];</div><div> for (int i = 1; i < A.length; i++) {</div><div> result = A[i] <span style="color: rgb(255, 0, 0);">^</span> result;</div><div> }</div><div> return result;</div><div> }</div><div>}</div></div><div><br/></div><div><br/></div></span>
</div></body></html>