class Solution(object):
def singleNonDuplicate(self, list):
low, high = 0 , len(list)1
while (low<high):
mid = low + (highlow)/2
if (list[mid]!=list[mid+1] and list[mid]!=list[mid1]):
return list[mid]
elif (mid%2 ==1 and list[mid]==list[mid1]):
low = mid+1
elif (mid%2 ==0 and list[mid]==list[mid+1]):
low = mid+1
else:
high = mid1
return list[low]
R
rudra_pratap
@rudra_pratap
1
Reputation
2
Posts
92
Profile views
0
Followers
0
Following
Posts made by rudra_pratap

Binary Search based approach in Python

RE: How can I remove the root?
I first find the leaf nodes and insert their value in a vector. After this, I make them NULL. As I call the nodes using reference, the root eventually gets deleted.
void find(TreeNode* &root, vector<int> &leaves) { if(root==NULL) return; if(root>left==NULL && root>right==NULL) { leaves.push_back(root>val); root=NULL; return; } find(root>left,leaves); find(root>right,leaves); } vector<vector<int>> findLeaves(TreeNode* root) { vector<vector<int>> all; vector<int> leaves(0); while(root) { find(root,leaves); all.push_back(leaves); leaves.clear(); } return all; }