Skip to content

Commit 270f37f

Browse files
540_Single_Element_in_a_Sorted_Array
1 parent c7c10ab commit 270f37f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def singleNonDuplicate(self, nums):
3+
"""
4+
:type nums: List[int]
5+
:rtype: int
6+
"""
7+
if nums[0] != nums[1]:
8+
return nums[0]
9+
for i in range(1, len(nums) - 1):
10+
if nums[i] != nums[i - 1] and nums[i] != nums[i + 1]:
11+
return nums[i]
12+
return nums[-1]
13+
14+

0 commit comments

Comments
 (0)