Skip to content

Commit 6a1cfd8

Browse files
author
Partho Biswas
committed
540 and 958
1 parent 29af4bf commit 6a1cfd8

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ I have solved quite a number of problems from several topics. See the below tabl
374374
|30| **[774. Minimize Max Distance to Gas Station](https://tinyurl.com/w2hznvj)** | [Python](https://tinyurl.com/wu6rdaw/774_Minimize_Max_Distance_to_Gas_Station.py), [Swift](https://tinyurl.com/wuja3c4/774_Minimize_Max_Distance_to_Gas_Station.swift) | [Vid 1](https://tinyurl.com/tjmrjgq), [Art 1](https://tinyurl.com/teqxwh8), [Art 2](https://tinyurl.com/szc6bjw), [Art 1](https://tinyurl.com/sfc5d2j) | Hard | I loved this problem. Very important |
375375
|31| **[1231. Divide Chocolate](https://tinyurl.com/rduxzj3)** | [Python](https://tinyurl.com/wu6rdaw/1231_Divide_Chocolate.py), [Swift](https://tinyurl.com/wuja3c4/1231_Divide_Chocolate.swift) | [Art 1](https://tinyurl.com/sl7w7cb), [Art 2](https://tinyurl.com/w9wbcyl), [Art 3](https://tinyurl.com/te6wq5e) | Hard | I loved this problem. Very important |
376376
|32| **[1268. Search Suggestions System](https://tinyurl.com/ybwcd5nx)** | [Python](https://tinyurl.com/wu6rdaw/1268_Search_Suggestions_System.py), [Swift](https://tinyurl.com/wuja3c4/1268_Search_Suggestions_System.swift) | [Art 1](https://tinyurl.com/yac3kvrp), [Art 2](https://tinyurl.com/y9u3g66q), [Art 3](https://tinyurl.com/yc2u3mrx) | Medium | I loved this problem. Very versatile, ca be solved in a lot of different ways |
377+
|33| **[540. Single Element in a Sorted Array](https://tinyurl.com/y78xdorh)** | [Python](https://tinyurl.com/wu6rdaw/540_Single_Element_in_a_Sorted_Array.py), [Swift](https://tinyurl.com/wuja3c4/1268_Search_Suggestions_System.swift) | | Medium | --- |
377378

378379

379380
</p>
@@ -425,6 +426,7 @@ Check this [golden](https://tinyurl.com/ujopecz) post.
425426
|34| **[572. Subtree of Another Tree](https://tinyurl.com/ybeerky9)**| [Python](https://tinyurl.com/wu6rdaw/572_Subtree_of_Another_Tree.py), [Swift](https://tinyurl.com/wuja3c4/572_Subtree_of_Another_Tree.swift) | [Art 1](https://tinyurl.com/y9epsrfa) | Easy(Not so) | |
426427
|35| **[314. Binary Tree Vertical Order Traversal](https://tinyurl.com/y7qx79no)**| [Python](https://tinyurl.com/wu6rdaw/314_Binary_Tree_Vertical_Order_Traversal.py), [Swift](https://tinyurl.com/wuja3c4/314_Binary_Tree_Vertical_Order_Traversal.swift) | [Vid 1](https://tinyurl.com/ybb6amfl) | Medium | |
427428
|36| **[987. Vertical Order Traversal of a Binary Tree](https://tinyurl.com/y8vqh9hk)**| [Python](https://tinyurl.com/wu6rdaw/987_Vertical_Order_Traversal_of_a_Binary_Tree.py), [Swift](https://tinyurl.com/wuja3c4/987_Vertical_Order_Traversal_of_a_Binary_Tree.swift) | [Vid 1](https://tinyurl.com/y8byrezh), [Art 1](https://tinyurl.com/yajsqrpp), [Art 2](https://tinyurl.com/yadjj6sy) | Medium | |
429+
|37| **[958. Check Completeness of a Binary Tree](https://tinyurl.com/yd6dsk88)**| [Python](https://tinyurl.com/wu6rdaw/958_Check_Completeness_of_a_Binary_Tree.py), [Swift](https://tinyurl.com/wuja3c4/958_Check_Completeness_of_a_Binary_Tree.swift) | [Art 1](https://tinyurl.com/y729zfol) | Medium | |
428430

429431
</p>
430432
</details>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
[1,1,2,3,3,4,4,8,8]
3+
0 4 8
4+
"""
5+
6+
7+
class Solution(object):
8+
def singleNonDuplicate(self, nums):
9+
"""
10+
:type nums: List[int]
11+
:rtype: int
12+
"""
13+
numLen = len(nums)
14+
if numLen == 1:
15+
return nums[-1]
16+
left, right = 0, numLen - 1
17+
while left <= right:
18+
mid = left + ((right - left) // 2)
19+
20+
if mid + 1 < numLen and nums[mid] == nums[mid + 1]:
21+
if (right - mid - 1) % 2 == 1:
22+
left = mid + 2
23+
else:
24+
right = mid - 1
25+
elif mid - 1 >= 0 and nums[mid] == nums[mid - 1]:
26+
if (mid - left - 1) % 2 == 1:
27+
right = mid - 2
28+
else:
29+
left = mid + 1
30+
else:
31+
return nums[mid]
32+
33+
return nums[left]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode(object):
3+
# def __init__(self, val=0, left=None, right=None):
4+
# self.val = val
5+
# self.left = left
6+
# self.right = right
7+
8+
from collections import deque
9+
10+
11+
class Solution(object):
12+
def isCompleteTree(self, root):
13+
"""
14+
:type root: TreeNode
15+
:rtype: bool
16+
"""
17+
bfsLevelOrder = [root]
18+
currentIdx = 0
19+
while bfsLevelOrder[currentIdx]:
20+
currentNode = bfsLevelOrder[currentIdx]
21+
bfsLevelOrder.append(currentNode.left)
22+
bfsLevelOrder.append(currentNode.right)
23+
currentIdx += 1
24+
return not any(bfsLevelOrder[currentIdx:])

0 commit comments

Comments
 (0)