question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
count-of-sub-multisets-with-bounded-sum
TypeScript Solution
typescript-solution-by-soraya1725-itai
Intuition\n\n\n# Approach\nThis function works by leveraging dynamic programming. The core idea is to maintain a list (dp) that keeps track of all possible sums
soraya1725
NORMAL
2023-10-25T16:09:08.365138+00:00
2023-10-25T16:09:08.365160+00:00
4
false
# Intuition\n\n\n# Approach\nThis function works by leveraging dynamic programming. The core idea is to maintain a list (dp) that keeps track of all possible sums that can be obtained using the numbers from the input array nums.\n\nInitially, the function sorts the numbers in descending order. It first handles any zero...
0
0
['TypeScript']
0
count-of-sub-multisets-with-bounded-sum
knapsack multiset
knapsack-multiset-by-dongts-5fap
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
dongts
NORMAL
2023-10-18T15:27:16.907039+00:00
2023-10-18T15:27:16.907065+00:00
51
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
count-of-sub-multisets-with-bounded-sum
[Python3] numpy dp
python3-numpy-dp-by-nottheswimmer-96of
A lot of the complicated looking parts are just small optimizations. There\'s also a lot of crud in here from attempted optimizations that didn\'t end up matter
nottheswimmer
NORMAL
2023-10-18T04:57:32.439530+00:00
2023-10-18T04:59:02.216385+00:00
11
false
A lot of the complicated looking parts are just small optimizations. There\'s also a lot of crud in here from attempted optimizations that didn\'t end up mattering, so feel free to learn by cleaning this up.\n\n```python\nimport numpy as np\n\nclass Solution:\n def countSubMultisets(self, nums: List[int], l: int, r:...
0
0
[]
0
count-of-sub-multisets-with-bounded-sum
scala
scala-by-len_master-9rqv
scala\nimport scala.collection.mutable\n\nobject Solution {\n def countSubMultisets(nums: List[Int], l: Int, r: Int): Int = {\n val M = 1000000007\n var
len_master
NORMAL
2023-10-16T10:14:08.118709+00:00
2023-10-16T10:14:08.118734+00:00
10
false
```scala\nimport scala.collection.mutable\n\nobject Solution {\n def countSubMultisets(nums: List[Int], l: Int, r: Int): Int = {\n val M = 1000000007\n var total = 0\n val cnt = mutable.HashMap.empty[Int, Int].withDefaultValue(0)\n nums.foreach(x => {\n total += x\n cnt(x) += 1\n })\n if (l...
0
0
['Scala']
0
count-of-sub-multisets-with-bounded-sum
90% (149ms) C++ solution following Google C++ Style Guide with Parallelization
90-149ms-c-solution-following-google-c-s-iemn
Motivation\n\nLets implement fast C++ solution based on DP sticking to the Google C++ Style Guide. We will have a look at rules which make our code readable and
ldimat
NORMAL
2023-10-16T00:37:27.907072+00:00
2023-10-16T11:26:52.346228+00:00
58
false
# Motivation\n\nLets implement fast C++ solution based on DP sticking to the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html). We will have a look at rules which make our code readable and robust. Also, we will try to use modern C++ constructions. In the end we will look into a parallelizatio...
0
0
['Dynamic Programming', 'C++']
0
count-of-sub-multisets-with-bounded-sum
My Solution
my-solution-by-hope_ma-zec5
\nclass Solution {\n public:\n int countSubMultisets(const vector<int> &nums, const int l, const int r) {\n constexpr int range = 2;\n constexpr int mod
hope_ma
NORMAL
2023-10-15T11:19:48.145296+00:00
2023-10-15T11:19:48.145319+00:00
22
false
```\nclass Solution {\n public:\n int countSubMultisets(const vector<int> &nums, const int l, const int r) {\n constexpr int range = 2;\n constexpr int mod = 1000000007;\n unordered_map<int, int> num_to_count;\n for (const int num : nums) {\n ++num_to_count[num];\n }\n \n auto itr_zero = num_...
0
0
[]
0
count-of-sub-multisets-with-bounded-sum
[c++] 100% [100ms]
c-100-100ms-by-lyronly-mwqi
\ntypedef long long ll;\nclass Solution {\npublic:\n const static int mod = (int)(1e9 +7);\n int countSubMultisets(vector<int>& nums, int l, int r) {\n
lyronly
NORMAL
2023-10-14T20:07:06.438649+00:00
2023-10-14T20:07:06.438668+00:00
67
false
```\ntypedef long long ll;\nclass Solution {\npublic:\n const static int mod = (int)(1e9 +7);\n int countSubMultisets(vector<int>& nums, int l, int r) {\n int n = nums.size();\n sort(nums.begin(), nums.end()); \n int m = nums.back();\n \n vector<int> cnt(m + 1, 0);\n ...
0
0
[]
0
count-of-sub-multisets-with-bounded-sum
Rust/C++ DP with Optimized Double Loop
rustc-dp-with-optimized-double-loop-by-x-r45k
Intuition\n Describe your first thoughts on how to solve this problem. \nNoticed that the sum of all numbers is no more 20000. When we add the numbers in sunseq
xiaoping3418
NORMAL
2023-10-14T18:54:17.135828+00:00
2023-10-14T18:54:17.135855+00:00
53
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nNoticed that the sum of all numbers is no more 20000. When we add the numbers in sunsequences, their sums are slowly growing to the up bound, which is no more than 20000.\nWe will use an array int dp[20001] to track the frequencies of the...
0
0
['Rust']
0
count-of-sub-multisets-with-bounded-sum
Javascript multi knapsack
javascript-multi-knapsack-by-henrychen22-wspb
\nconst counter = (a_or_s) => { let m = new Map(); for (const x of a_or_s) m.set(x, m.get(x) + 1 || 1); return m; };\n\nconst mod = 1e9 + 7;\nconst countSubMult
henrychen222
NORMAL
2023-10-14T17:53:04.773984+00:00
2023-10-14T17:53:04.774012+00:00
44
false
```\nconst counter = (a_or_s) => { let m = new Map(); for (const x of a_or_s) m.set(x, m.get(x) + 1 || 1); return m; };\n\nconst mod = 1e9 + 7;\nconst countSubMultisets = (a, l, r) => {\n let f = Array(r + 1).fill(0), m = counter(a), res = 0;\n f[0] = 1;\n for (const [x, occ] of m) {\n if (x == 0) {\n ...
0
0
['Dynamic Programming', 'JavaScript']
0
count-of-sub-multisets-with-bounded-sum
DP (Knapsack)
dp-knapsack-by-dnitin28-258c
\n\n# Code\n\nclass Solution {\npublic:\n const int mod = 1e9 + 7;\n int countSubMultisets(vector<int>& nums, int l, int r) {\n int n = nums.size()
gyrFalcon__
NORMAL
2023-10-14T17:35:47.277703+00:00
2023-10-14T17:35:47.277731+00:00
181
false
\n\n# Code\n```\nclass Solution {\npublic:\n const int mod = 1e9 + 7;\n int countSubMultisets(vector<int>& nums, int l, int r) {\n int n = nums.size();\n int sum = 0, mx = 0;\n vector<int> freq(2e4 + 1);\n set<int> s;\n for(int i=0;i<n;i++){\n freq[nums[i]] ++;\n ...
0
0
['C++']
0
count-of-sub-multisets-with-bounded-sum
🔥🔥🔥 Python Simple Solution 🔥🔥🔥
python-simple-solution-by-hululu0405-0dof
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
hululu0405
NORMAL
2023-10-14T17:09:47.003754+00:00
2023-10-14T17:09:47.003777+00:00
75
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(nr)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(r)\n<!-- Add your space complexity here, e.g. ...
0
0
['Python3']
0
count-of-sub-multisets-with-bounded-sum
🔥🔥🔥 Python Simple Solution 🔥🔥🔥
python-simple-solution-by-hululu0405-qcz2
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
hululu0405
NORMAL
2023-10-14T17:09:46.153107+00:00
2023-10-14T17:09:46.153123+00:00
35
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(nr)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(r)\n<!-- Add your space complexity here, e.g. ...
0
0
['Python3']
0
count-of-sub-multisets-with-bounded-sum
dp knackbag
dp-knackbag-by-alkut-pnm0
Intuition\ncount of unique positive numbers <= sqrt(nums[i]) \n\n# Complexity\n- Time complexity: O(r * sqrt(sum(nums[i])))\n\n- Space complexity: O(r)\n\n# Co
alkut
NORMAL
2023-10-14T16:47:50.965479+00:00
2023-10-14T16:47:50.965503+00:00
133
false
# Intuition\ncount of unique positive numbers <= $$ sqrt(nums[i]) $$\n\n# Complexity\n- Time complexity: $$O(r * sqrt(sum(nums[i])))$$\n\n- Space complexity: $$O(r)$$\n\n# Code\n```\nclass Solution {\npublic:\n int countSubMultisets(const vector<int> &nums, int l, int r) {\n map<int, int> m;\n long lon...
0
0
['C++']
0
count-of-sub-multisets-with-bounded-sum
2D DP accepted solution Java
2d-dp-accepted-solution-java-by-kartikey-x1me
\n# Code\n\nclass Solution {\n\n int MOD = (int) 1e9 + 7;\n\n HashMap<Integer, Integer> map;\n\n int dp[][];\n\n int solve(ArrayList<Integer> al, in
kartikeysemwal
NORMAL
2023-10-14T16:40:38.351920+00:00
2023-10-14T16:40:38.351941+00:00
92
false
\n# Code\n```\nclass Solution {\n\n int MOD = (int) 1e9 + 7;\n\n HashMap<Integer, Integer> map;\n\n int dp[][];\n\n int solve(ArrayList<Integer> al, int l, int r, int index, int sum) {\n if (sum > r) {\n return 0;\n }\n\n long ans = 0;\n\n // if (sum >= l && sum <= r) ...
0
0
['Dynamic Programming', 'Java']
0
count-of-sub-multisets-with-bounded-sum
Java dfs(r) - dfs(l-1) = ans
java-dfsr-dfsl-1-ans-by-scsonic-4woh
Intuition\n1. reorder the nums into: uniqueNums and cnt, resolv the multi-set problem\n2. make dfs(at, target) means index at i, remain sum = target, return how
scsonic
NORMAL
2023-10-14T16:37:26.888372+00:00
2023-10-14T17:03:20.773706+00:00
244
false
# Intuition\n1. reorder the nums into: uniqueNums and cnt, resolv the multi-set problem\n2. make dfs(at, target) means index at i, remain sum = target, return how many ans in it\n3. return dfs(r) - dfs(l-1) = ans\n\n# Approach\ntwo key point in dfs:\n\n def dfs(at, target)\n # 1. do not select nums[at]\n ...
0
0
['Memoization', 'Java']
0
count-of-sub-multisets-with-bounded-sum
JS Solution - Knapsack - It somehow got accepted LOL
js-solution-knapsack-it-somehow-got-acce-3rm5
I solved it as a variant of snapsack, which may not be efficient, but it somehow got accepted.\nAt first, I used Maps for sumsMapPre and sumsMapCur, and it hit
CuteTN
NORMAL
2023-10-14T16:08:52.473053+00:00
2023-10-14T16:37:03.627370+00:00
182
false
I solved it as a variant of **snapsack**, which may not be efficient, but it somehow got accepted.\nAt first, I used **Maps** for `sumsMapPre` and `sumsMapCur`, and it hit me with a TLE. So I switch to arrays, I\'m a little surprised that this small optimization can beat the judge.\n\n# Complexity\n- let `n = nums.leng...
0
0
['Dynamic Programming', 'JavaScript']
0
count-of-sub-multisets-with-bounded-sum
Hard DP | python
hard-dp-python-by-betoscl-jymv
Approach\nThe number of different numbers is at most $\sqrt n$ so we can iterate over all the different numbers and make a DP , the problem here is that even th
BetoSCL
NORMAL
2023-10-14T16:06:19.861465+00:00
2023-10-14T16:32:33.016184+00:00
514
false
# Approach\nThe number of different numbers is at most $\\sqrt n$ so we can iterate over all the different numbers and make a DP , the problem here is that even the different numbers are relatively small, we still have to update the DP in a clever way in order to reduce the complexity.\n\nThe $DP$ transitions are:\n\n$...
0
0
['Python3']
1
single-element-in-a-sorted-array
Java | C++ | Python3 | Easy explanation | O(logn) | O(1)
java-c-python3-easy-explanation-ologn-o1-71nt
\nEXPLANATION:-\nSuppose array is [1, 1, 2, 2, 3, 3, 4, 5, 5]\nwe can observe that for each pair, \nfirst element takes even position and second element takes o
logan138
NORMAL
2020-05-12T08:18:59.747723+00:00
2024-09-26T10:32:52.786027+00:00
57,755
false
```\nEXPLANATION:-\nSuppose array is [1, 1, 2, 2, 3, 3, 4, 5, 5]\nwe can observe that for each pair, \nfirst element takes even position and second element takes odd position\nfor example, 1 is appeared as a pair,\nso it takes 0 and 1 positions. similarly for all the pairs also.\n\nthis pattern will be missed when sing...
1,222
7
['C++', 'Java', 'Python3']
72
single-element-in-a-sorted-array
Day 52 || Binary Search || Easiest Beginner Friendly Sol
day-52-binary-search-easiest-beginner-fr-sqyl
Intuition of this Problem:\nSince every element in the sorted array appears exactly twice except for the single element, we know that if we take any element at
singhabhinash
NORMAL
2023-02-21T01:15:03.395992+00:00
2023-04-01T10:19:49.048468+00:00
68,024
false
# Intuition of this Problem:\nSince every element in the sorted array appears exactly twice except for the single element, we know that if we take any element at an even index (0-indexed), the next element should be the same. Similarly, if we take any element at an odd index, the previous element should be the same. Th...
577
5
['Array', 'Binary Search', 'C++', 'Java', 'Python3']
26
single-element-in-a-sorted-array
Java Binary Search, short (7l), O(log(n)) w/ explanations
java-binary-search-short-7l-ologn-w-expl-iwqg
All credits go to @Penghuan who thought of using the pairs wisely.\n\nThis method seems to be a bit simpler to understand, since it doesn't start with the left
baguette
NORMAL
2017-04-24T18:10:27.569000+00:00
2018-10-23T19:06:48.740691+00:00
49,506
false
All credits go to [@Penghuan](/post/175763) who thought of using the pairs wisely.\n\nThis method seems to be a bit simpler to understand, since it doesn't start with the left half and stays a little bit closer to the conventional solutions.\n\n```\n public static int singleNonDuplicate(int[] nums) {\n int sta...
393
15
[]
54
single-element-in-a-sorted-array
Short, compare nums[i] with nums[i^1]
short-compare-numsi-with-numsi1-by-stefa-5wdy
Simply find the first index whose "partner index" (the index xor 1) holds a different value.\n\nRuby:\n\ndef single_non_duplicate(nums)\n nums[(0..nums.size).b
stefanpochmann
NORMAL
2017-03-17T19:54:16.158000+00:00
2018-10-20T03:00:09.308060+00:00
19,105
false
Simply find the first index whose "partner index" (the index xor 1) holds a different value.\n\n**Ruby:**\n```\ndef single_non_duplicate(nums)\n nums[(0..nums.size).bsearch { |i| nums[i] != nums[i^1] }]\nend\n```\n**Python**\n\n def singleNonDuplicate(self, nums):\n lo, hi = 0, len(nums) - 1\n while l...
292
5
[]
34
single-element-in-a-sorted-array
✅ [C++/Python] 7 Simple Solutions w/ Explanation | Brute + Hashmap + XOR + Linear +2 Binary Search
cpython-7-simple-solutions-w-explanation-h5yo
We are given a sorted array nums consisting of elements each of which occurs twice except one. We need to return that element which occurs once.\n\n\nTable of C
archit91
NORMAL
2021-11-20T02:18:49.178042+00:00
2021-11-20T19:43:08.872935+00:00
10,441
false
We are given a sorted array `nums` consisting of elements each of which occurs twice except one. We need to return that element which occurs once.\n\n<details>\n<summary><i>Table of Contents</i></summary>\n<p align=middle>\n<table>\n <tr>\n <th>No.</th>\n <th>Approach</th>\n <th>Time</th>\n <th>Space</th>\...
238
11
[]
20
single-element-in-a-sorted-array
Java Binary Search O(log(n)) Shorter Than Others
java-binary-search-ologn-shorter-than-ot-5e0x
My solution using binary search. lo and hi are not regular index, but the pair index here. Basically you want to find the first even-index number not followed b
less_is_more_duluth
NORMAL
2017-03-10T00:08:14.302000+00:00
2018-10-07T18:34:34.798352+00:00
32,596
false
My solution using binary search. lo and hi are not regular index, but the pair index here. Basically you want to find the first even-index number not followed by the same number.\n```\npublic class Solution {\n public int singleNonDuplicate(int[] nums) {\n // binary search\n int n=nums.length, lo=0, hi...
196
5
[]
24
single-element-in-a-sorted-array
✅ [C++] EASY Intuitive Solution|| 2 approaches || Binary Search || TC:O(log(N)), SC:O(1)
c-easy-intuitive-solution-2-approaches-b-eda5
Hello everyone, I hope you all are doing great!\n\nNOTE: If you found this post helpful, then please do upvote it!\n\nBrute Force Approach: (XOR) Since we know
riemeltm
NORMAL
2021-11-20T02:05:06.160607+00:00
2021-11-20T05:11:40.747025+00:00
7,112
false
Hello everyone, I hope you all are doing great!\n\n***NOTE: If you found this post helpful, then please do upvote it!***\n\n**Brute Force Approach: (XOR)** Since we know every element occurs exactly twice, where as our target element occurs once, then we can simple take xor of all the elements of the array. In the end ...
163
20
[]
13
single-element-in-a-sorted-array
✔️ [C++] Easy and Concise O(logn) Solution (W/ Explanation)
c-easy-and-concise-ologn-solution-w-expl-t6oq
Hello everyone, firstly thanks for refering to my solution in advance :)\n\nAPPROACH : \n So, the array has all the elements repeating twice except for one elem
Mythri_Kaulwar
NORMAL
2021-11-20T02:01:08.507263+00:00
2021-11-20T02:17:48.287243+00:00
6,312
false
Hello everyone, firstly thanks for refering to my solution in advance :)\n\n**APPROACH :** \n* So, the array has all the elements repeating twice except for one element which appears only once and the array is sorted. \n* This means that in every number that\'s repeated, the first number is at an even index (index%2==0...
125
0
['C', 'Binary Tree', 'C++']
11
single-element-in-a-sorted-array
Java Binary Search | Beats 100% | Most Intutive | Explanation Using Image
java-binary-search-beats-100-most-intuti-igno
Intution: keep dividing your array in two halves and check in which half there are odd number of elements...that will be your required part.\n\n\n\n\n\n\n\n\ncl
Chaitanya1706
NORMAL
2021-11-20T03:00:23.225069+00:00
2022-06-01T07:27:01.322285+00:00
5,990
false
**Intution:** keep dividing your array in two halves and check in which half there are odd number of elements...that will be your required part.\n\n\n\n\n![image](https://assets.leetcode.com/users/images/f7fc208d-13da-423c-8069-e50c7c810c0d_1637377156.442444.jpeg)\n\n\n```\nclass Solution {\n public int singleNonDup...
113
2
['Binary Tree', 'Java']
9
single-element-in-a-sorted-array
Python Binary Search O(logn) - explained
python-binary-search-ologn-explained-by-43ag7
If every element in the sorted array were to appear exactly twice, they would occur in pairs at indices i, i+1 for all even i. \n\nEquivalently, nums[i] = nums[
cjporteo
NORMAL
2020-05-12T09:42:14.719822+00:00
2020-05-12T10:56:29.376280+00:00
7,446
false
If every element in the sorted array were to appear exactly twice, they would occur in pairs at indices `i`, `i+1` for all **even** `i`. \n\nEquivalently, `nums[i] = nums[i+1]` and `nums[i+1] != nums[i+2]` for all **even** `i`.\n\nWhen we insert the unique element into this list, the indices of all the pairs following ...
113
0
['Binary Search', 'Python']
12
single-element-in-a-sorted-array
[C++] O(log n) time O(1) space | Simple and clean | Use xor to keep track of odd even pair
c-olog-n-time-o1-space-simple-and-clean-hjyqf
nums[mid] == nums[mid ^ 1] for odd position compares with the previous number; for even position compares with the next number. The unique number must be at eve
sonugiri
NORMAL
2020-05-12T07:07:48.788912+00:00
2020-05-12T09:37:47.774537+00:00
8,025
false
**nums[mid] == nums[mid ^ 1]** for odd position compares with the previous number; for even position compares with the next number. The unique number must be at even position.\n \n```\nint singleNonDuplicate(vector<int>& nums) {\n\tint start=0, end = nums.size()-1, mid;\n\twhile( start < end ) {\n\t\tmid = start + (end...
107
2
[]
16
single-element-in-a-sorted-array
C++ Solution O(logn) with detailed explanation
c-solution-ologn-with-detailed-explanati-gcx6
\nWe use binary search to solve this.\n\nThe problem of using binary search is how to determine the conditions inside the while loop?\n\nWell this logic maynot
leodicap99
NORMAL
2020-05-12T10:41:41.312989+00:00
2020-05-12T10:41:41.313046+00:00
4,364
false
```\nWe use binary search to solve this.\n\nThe problem of using binary search is how to determine the conditions inside the while loop?\n\nWell this logic maynot come that intuitively but if u observe a few examples u will quickly get the idea.\n\nLet num=[1,1,2,3,3,4,4,8,8]\n 0,1,2,3,4,5,6,7,8 <----indices\n\...
69
2
['C', 'C++']
4
single-element-in-a-sorted-array
Java Binary Search with Detailed Explanation
java-binary-search-with-detailed-explana-2vmn
Let's start with two simple observations.\n\nExample 1: An array with length 2*4 + 1\nleft = 0, right = 8, mid = 4.\nIf the single element X is on the left hand
coshchen
NORMAL
2017-12-13T16:24:11.479000+00:00
2018-10-19T04:38:06.097890+00:00
5,055
false
Let's start with two simple observations.\n\n**Example 1**: An array with length ```2*4 + 1```\n```left = 0```, ```right = 8```, ```mid = 4```.\nIf the single element ```X``` is on the left hand side, ```nums[mid] == nums[mid-1]```: \n```[1, 1, X, 2, 2(mid), 3, 3, 4, 4]```\nIf the single element ```X``` is on the right...
69
1
[]
6
single-element-in-a-sorted-array
[Python] 3 Simple Approaches with Explanation
python-3-simple-approaches-with-explanat-dduw
Approach 1: (Optimised) Brute Force\n\nThere are a few ways to brute force a solution. One way is to count the number of times each element appears in the array
zayne-siew
NORMAL
2021-11-20T02:41:07.779475+00:00
2021-11-20T07:35:19.765310+00:00
4,849
false
### Approach 1: (Optimised) Brute Force\n\nThere are a few ways to brute force a solution. One way is to count the number of times each element appears in the array, and then return the value with a counter of 1.\n\n```python\nclass Solution:\n def singleNonDuplicate(self, nums: List[int]) -> int:\n counts = ...
65
2
['Binary Tree', 'Python', 'Python3']
11
single-element-in-a-sorted-array
🗓️ Daily LeetCoding Challenge November, Day 20
daily-leetcoding-challenge-november-day-h65t1
This problem is the Daily LeetCoding Challenge for November, Day 20. Feel free to share anything related to this problem here! You can ask questions, discuss wh
leetcode
OFFICIAL
2021-11-20T00:00:24.945182+00:00
2021-11-20T00:00:24.945231+00:00
5,615
false
This problem is the Daily LeetCoding Challenge for November, Day 20. Feel free to share anything related to this problem here! You can ask questions, discuss what you've learned from this problem, or show off how many days of streak you've made! --- If you'd like to share a detailed solution to the problem, please ...
39
3
[]
34
single-element-in-a-sorted-array
Easy Binary Search Explanation | O(logn) | O(1)
easy-binary-search-explanation-ologn-o1-s9x8z
Intuition\nLet\'s look at an example array [3,3,4,4,5,6,6,7,7]. We look at indicies 0, 2, 4, 6, 8 and check if the number is equal to the number on its right.\n
fromdihpout
NORMAL
2023-02-21T00:53:21.372228+00:00
2023-02-21T00:53:21.372270+00:00
8,524
false
# Intuition\nLet\'s look at an example array `[3,3,4,4,5,6,6,7,7]`. We look at indicies `0, 2, 4, 6, 8` and check if the number is equal to the number on its right.\n```\n index: 0 1 2 3 4 5 6 7 8\n nums: 3 3 4 4 5 6 6 7 7\nmatches: T T F F F\n```\nAt the singleton number, the numb...
35
3
['Python3']
10
single-element-in-a-sorted-array
✅☑️ Best C++ 5 Solution || Binary Search || XOR || Hash Table || Brute Force->Optimize.
best-c-5-solution-binary-search-xor-hash-32a7
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can solve this question using Multiple Approaches. (Here I have explained all the po
its_vishal_7575
NORMAL
2023-02-15T16:04:33.469570+00:00
2023-02-15T16:04:33.469617+00:00
1,772
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can solve this question using Multiple Approaches. (Here I have explained all the possible solutions of this problem).\n\n1. Solved using Array(Two Nested Loop). Brute Force Approach.\n2. Solved using Array + Hash Table(Unordered map)....
32
0
['Array', 'Hash Table', 'Binary Search', 'Bit Manipulation', 'C++']
1
single-element-in-a-sorted-array
Java Code by using binary search O(log(n))
java-code-by-using-binary-search-ologn-b-chui
public int singleNonDuplicate(int[] nums) {\n int low = 0;\n int high = nums.length-1;\n \n while(low < high) {\n int mid
dhawal9035
NORMAL
2017-03-09T03:05:40.569000+00:00
2018-09-22T06:54:08.147224+00:00
10,667
false
public int singleNonDuplicate(int[] nums) {\n int low = 0;\n int high = nums.length-1;\n \n while(low < high) {\n int mid = low + (high - low)/2;\n if(nums[mid] != nums[mid+1] && nums[mid] != nums[mid-1])\n return nums[mid];\n else if(nums[mid]...
30
1
[]
5
single-element-in-a-sorted-array
C++ Solution with step by step explanation.
c-solution-with-step-by-step-explanation-qaev
Attacking the problem\nYou start with B.S. as the question is tagged as B.S. and then think that the array is sorted so B.S. it is.\nStuck!! How do I know if I
tars2412
NORMAL
2021-06-01T06:55:43.148090+00:00
2021-08-24T06:38:00.228913+00:00
1,384
false
**Attacking the problem**\nYou start with B.S. as the question is tagged as B.S. and then think that the array is sorted so B.S. it is.\n**Stuck!! How do I know if I go left or right from the middle :(**\nOkay jokes apart this is a really good problem on B.S. and let us carefully analyse what we are given.\nThe array i...
26
0
['C', 'Binary Tree']
4
single-element-in-a-sorted-array
Java Binary Search O(lgN) : clear, easy, explained, no tricks
java-binary-search-olgn-clear-easy-expla-bt39
First, the code:\njava\npublic class Solution {\n public int singleNonDuplicate(int[] nums) {\n int n = nums.length;\n int lo = 0, hi = n;\n
vegito2002
NORMAL
2017-07-26T00:45:11.535000+00:00
2018-09-26T07:27:46.454322+00:00
2,963
false
First, the code:\n```java\npublic class Solution {\n public int singleNonDuplicate(int[] nums) {\n int n = nums.length;\n int lo = 0, hi = n;\n while (lo < hi) {\n int mid = lo + (hi - lo) / 2;\n if ((mid % 2 == 0 && mid + 1 < n && nums[mid] == nums[mid + 1]) ||\n ...
25
0
[]
3
single-element-in-a-sorted-array
Multiple_Approaches.py
multiple_approachespy-by-jyot_150-hgqp
UPVOTE IF YOU LIKE SOLN \n\n# Approach\n Brute Force -> Optimization\n\n# Complexity\n- Time complexity:\nO(n) --> O(log n)\n# Codes\n```\n//Brute Force OP\ncla
jyot_150
NORMAL
2023-02-21T03:15:46.558698+00:00
2023-02-21T14:46:05.178413+00:00
1,235
false
<h3>UPVOTE IF YOU LIKE SOLN</h3>\n\n# Approach\n<h4>Brute Force -> Optimization\n\n# Complexity\n- Time complexity:\n$$O(n)$$ --> $$O(log n)$$\n# Codes\n```\n//Brute Force OP\nclass Solution {\npublic:\n int singleNonDuplicate(vector<int>& nums) {\n for(int p=0;p<nums.size()-1;p+=2){\n if(nums[p]!=...
24
1
['Python3']
3
single-element-in-a-sorted-array
Java Super Elegent solution (log(n) Runtime O(1) extra space, bit trick). [Detailed explanation]
java-super-elegent-solution-logn-runtime-ol9e
Idea behind the solution:\n\n1. If the current index in the binary search is I (0 index based), the we can decide the next search space based on:\n\ta. If I is
cool_rohan
NORMAL
2020-05-12T08:34:51.576742+00:00
2020-05-12T12:51:43.806502+00:00
1,933
false
Idea behind the solution:\n\n1. If the current index in the binary search is `I` (0 index based), the we can decide the next search space based on:\n\ta. If `I` is even, and `nums[I] == nums[I + 1]`, then size of subarray `[0...I-1]` (left side) is even (since the element count is `I`), so left side does not contain t...
23
4
['Binary Search', 'Java']
4
single-element-in-a-sorted-array
🚀Simplest Solution🚀||🔥Binary Search||🔥C++🔥|| Python3
simplest-solutionbinary-searchc-python3-pj7k7
Consider\uD83D\uDC4D\n\n Please Upvote If You Find It Helpful\n\n# Intuition \nIntitution is very simple we have to find the which appears on
naman_ag
NORMAL
2023-02-21T03:42:23.924018+00:00
2023-02-21T03:42:23.924061+00:00
2,259
false
# Consider\uD83D\uDC4D\n```\n Please Upvote If You Find It Helpful\n```\n# Intuition \nIntitution is very simple we have to find the which appears once.\nWe can see in array it follows a pattern all the duplicate pairs are at **Even and Odd positions** this pattern is not satisfied when there is a si...
20
0
['Array', 'Binary Search', 'Python', 'C++', 'Python3']
1
single-element-in-a-sorted-array
✅ [Java] EASY Intuitive Sol | Full Explanation | 100% Faster | Bit Manipulation | Binary Search
java-easy-intuitive-sol-full-explanation-mqsq
Hello everyone, I hope you all are doing great.\nNote: If you found this post helpful then please do upvote!\n\nIn this post i\'ll explain 4 approach from worst
kumarav1nash
NORMAL
2021-11-20T08:47:41.954454+00:00
2021-11-20T14:39:27.409205+00:00
1,156
false
Hello everyone, I hope you all are doing great.\n**Note: If you found this post helpful then please do upvote!**\n\nIn this post i\'ll explain 4 approach from worst to best time complexity, and i\'ll also i\'ll try to explain the intution behind this.\nBefore we proceed to various approaches let\'s keep this thing in m...
20
0
['Bit Manipulation', 'Binary Tree', 'Java']
3
single-element-in-a-sorted-array
Python beats 100%
python-beats-100-by-ethuoaiesec-xwkw
Use binary search. It mid is even, then check nums[mid] and nums[mid + 1]. If they are equal, then the target must be on the right half. Similarly for mid is od
ethuoaiesec
NORMAL
2020-12-04T05:27:31.360357+00:00
2020-12-04T05:27:59.717507+00:00
1,616
false
Use binary search. It mid is even, then check nums[mid] and nums[mid + 1]. If they are equal, then the target must be on the right half. Similarly for mid is odd, check nums[mid] and nums[mid - 1].\n```\nclass Solution(object):\n def singleNonDuplicate(self, nums):\n """\n :type nums: List[int]\n ...
18
0
['Binary Tree', 'Python', 'Python3']
5
single-element-in-a-sorted-array
✅JAVA || C++ || PYTHON || 🚀log n || 💯Beginners can Understand ||🔥Easy & Intuitive
java-c-python-log-n-beginners-can-unders-kae6
Upvote if you like the Soltution and Explanation :)\n\n# Intuition \n- Element in pairs, even index, odd index, so find mid and check if it\'s at correct positi
AshLuvCode
NORMAL
2023-02-21T00:51:08.933377+00:00
2023-02-21T13:37:18.935934+00:00
3,236
false
**Upvote if you like the Soltution and Explanation :)**\n\n# Intuition \n- Element in pairs, even index, odd index, so find mid and check if it\'s at correct position or not.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- I already handled the corner cases separately.\n\n- if nums...
17
0
['Binary Search', 'C', 'Binary Tree', 'Python', 'Java']
3
single-element-in-a-sorted-array
[Python] short binary search, explained
python-short-binary-search-explained-by-67scc
Straightforward way is to just iterate over all elements in O(n). There is smarter binary search solution. For example we have aa bb cc dd ee ff gg h ii jj kk.
dbabichev
NORMAL
2021-11-20T06:44:24.664253+00:00
2021-11-20T06:44:24.664287+00:00
391
false
Straightforward way is to just iterate over all elements in `O(n)`. There is smarter binary search solution. For example we have `aa bb cc dd ee ff gg h ii jj kk`. Let us find middle element, but shift it by one if number of element in the left part is odd: we always consider even number of elements in the left part. T...
16
1
['Binary Search']
2
single-element-in-a-sorted-array
Java - Binary Search O(log N) time and O(1) memory
java-binary-search-olog-n-time-and-o1-me-1jsm
\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int N = nums.length;\n if(N == 1)\n return nums[0];\n \n
cpp_to_java
NORMAL
2020-05-12T07:08:21.668852+00:00
2020-05-14T08:57:13.953741+00:00
1,169
false
```\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int N = nums.length;\n if(N == 1)\n return nums[0];\n \n int left = 0;\n int right = N - 1;\n int mid;\n \n while(left < right){\n mid = left + ((right - left) >> 1);\n...
14
1
[]
3
single-element-in-a-sorted-array
C++ binary search
c-binary-search-by-hellotest-5rzj
\nclass Solution {\npublic:\n int singleNonDuplicate(vector<int>& nums) {\n int n = nums.size(), left = 0, right = n - 1;\n while (left < right
hellotest
NORMAL
2017-03-09T03:28:23.724000+00:00
2018-08-09T00:15:03.397146+00:00
7,850
false
```\nclass Solution {\npublic:\n int singleNonDuplicate(vector<int>& nums) {\n int n = nums.size(), left = 0, right = n - 1;\n while (left < right) {\n int mid = left + (right - left) / 2;\n if (mid % 2 == 0) {\n if (nums[mid] == nums[mid-1]) right = mid - 2;\n ...
14
0
[]
8
single-element-in-a-sorted-array
Python | Binary Search | O(logn) time & O(1) space | Simple Solution With Explanation
python-binary-search-ologn-time-o1-space-gj7f
Logic\n1. Since we don\'t have any target element to search for so we can\'t directly decide which part of array we need to look for single element.\n2. Since w
akash3anup
NORMAL
2021-11-20T05:33:42.150073+00:00
2022-03-11T07:24:13.312797+00:00
700
false
# Logic\n1. Since we don\'t have any target element to search for so we can\'t directly decide which part of array we need to look for single element.\n2. Since we know that every element has a duplicate except one so we can commit that the length of array will always be odd.\n3. Now, based on the above logic we can de...
12
1
['Binary Search', 'Binary Tree', 'Python']
2
single-element-in-a-sorted-array
Visually Explained, Binary Search Solution.
visually-explained-binary-search-solutio-3kot
\u200B\nMain points from Question :\n It\'s been stated that elements appear exactly twice except for one element which is to be found.\n Solution must run in
Devansh2907
NORMAL
2024-02-25T12:32:53.866150+00:00
2024-02-25T12:32:53.866180+00:00
458
false
\u200B\n**Main points from Question :**\n* It\'s been stated that elements appear exactly twice except for one element which is to be found.\n* Solution must run in O(log n) time and O(1) space.\n\u200B\n**Intuition developed :**\n* So from what we can discern from the given inputs that the inputs will be same for e...
11
0
['Binary Tree', 'Java']
2
single-element-in-a-sorted-array
⭐ Binary Search - Time Complexity + Space Complexity + Explanation ⭐
binary-search-time-complexity-space-comp-mh9d
Time Complexity - Binary search takes O(logN base 2) time.\nSpace Complexity - Space taken is O(1).\nExplanation - To solve this problem, we use a modified vers
psy_0
NORMAL
2022-10-27T05:47:33.107504+00:00
2022-10-27T05:49:19.565899+00:00
1,499
false
Time Complexity - Binary search takes O(logN base 2) time.\nSpace Complexity - Space taken is O(1).\nExplanation - To solve this problem, we use a modified version of binary search.\nWe know that mid is our target element, if the element is not equal to either its next or previous element (since array is sorted array)....
11
0
['Array', 'C', 'Binary Tree', 'C++']
3
single-element-in-a-sorted-array
Python O(lg n) by binary search 85%+ [w/ Visualization]
python-olg-n-by-binary-search-85-w-visua-et3v
Python O(lg n) by binary search\n\n---\n\nHint:\n\nGroup each numbers in pairs, and launch binary search to locate the first index of mis-matched pair.\n\n---\n
brianchiang_tw
NORMAL
2020-05-12T09:09:32.877342+00:00
2020-05-12T09:53:58.486989+00:00
1,025
false
Python O(lg n) by binary search\n\n---\n\nHint:\n\nGroup each numbers in pairs, and launch binary search to locate the first index of mis-matched pair.\n\n---\n\n**Illustration and Visualization**:\n\n![image](https://assets.leetcode.com/users/brianchiang_tw/image_1589277233.png)\n\n---\n\n**Implementation** by binary ...
11
0
['Binary Search', 'Python', 'Python3']
1
single-element-in-a-sorted-array
Very easy solution in C++ || Basic approach (beats 100%)
very-easy-solution-in-c-basic-approach-b-0cqw
iam explained indetail in my website and youtube vedio if you have more clearity on this problem and approachs visite the below website and youtube channel:\nWE
vinaykumar333j
NORMAL
2024-11-26T17:31:40.919621+00:00
2024-11-26T17:31:40.919646+00:00
386
false
iam explained indetail in my website and youtube vedio if you have more clearity on this problem and approachs visite the below website and youtube channel:\nWEBSITE:\nhttps://vinayhac.blogspot.com/2023/06/540.%20Single%20Element%20in%20a%20Sorted%20Array.html\nYOUTUBE VEDIO:\nhttps://youtu.be/vGtAZA62xC8\n\nin this pr...
10
0
['Math']
0
single-element-in-a-sorted-array
✅ Multiple Javascript Solutions || Brute Force O(n) O(1) || Binary Search O(logn) O(1) || XOR
multiple-javascript-solutions-brute-forc-xiu4
Feel free to ask Q\'s...\n#happytohelpu\n\nDo upvote if you find this solution useful. Happy Coding!\n\nSolution 1 : Brute Force (with XOR)\nTime Complexity : O
lakshmikant4u
NORMAL
2023-02-21T06:56:56.025455+00:00
2023-04-10T19:31:46.996057+00:00
1,175
false
**Feel free to ask Q\'s...**\n*#happytohelpu*\n\n***Do upvote if you find this solution useful. Happy Coding!***\n\n**Solution 1 : Brute Force (with XOR)**\nTime Complexity : O(n)\nSpace Complexity : O(1)\n\n```\n\nconst singleNonDuplicate = nums => nums.reduce((a, b) => a ^ b); // XOR to get the single value\n\n```\n\...
10
0
['Binary Search', 'Bit Manipulation', 'Binary Tree', 'Iterator', 'JavaScript']
0
single-element-in-a-sorted-array
C++✅✅ | Faster🧭 than 85%🔥| Hashing🆗 | Very Easy Code | Clean code |
c-faster-than-85-hashingok-very-easy-cod-2c1y
\n\n# Code\n# PLEASE DO UPVOTE!!!!!\n\n\nclass Solution {\npublic:\n int singleNonDuplicate(vector<int>& nums) {\n\n unordered_map<int,int>mpp;\n f
mr_kamran
NORMAL
2023-02-21T01:44:31.243367+00:00
2023-02-21T01:44:31.243414+00:00
2,265
false
\n\n# Code\n# PLEASE DO UPVOTE!!!!!\n```\n\nclass Solution {\npublic:\n int singleNonDuplicate(vector<int>& nums) {\n\n unordered_map<int,int>mpp;\n for(auto i:nums) mpp[i]++;\n \n for(auto it:mpp)\n if(it.second==1) return it.first;\n \n return -1;\n }\n};\n\n\n```
10
1
['C++']
3
single-element-in-a-sorted-array
C++ | Clean Code (5 Lines) | Easy to understand | XOR Method | Well explained
c-clean-code-5-lines-easy-to-understand-4n293
Pls upvote the thread if you found it helpful.\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n We know :-\n - XOR(x,x)
forkadarshp
NORMAL
2023-02-21T01:07:08.009778+00:00
2023-02-21T10:14:55.092105+00:00
2,337
false
**Pls upvote the thread if you found it helpful.**\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n We know :-\n - XOR(x,x) = 0\n - XOR(x,0) = x\nUsing this the **repeating elements** will become 0 and the element that is **present once** will be left.\nIterate over...
10
4
['Array', 'Math', 'Binary Search', 'Bit Manipulation', 'C++']
4
single-element-in-a-sorted-array
C++ Simple and Clean Solutions, O(logn), With Explanation
c-simple-and-clean-solutions-ologn-with-6g66q
O(logn) Binary Search Solution:\nExplanation:\nFor a regular sorted array where each element is double, be have the first in an even index and the second in an
yehudisk
NORMAL
2021-08-03T10:13:53.434614+00:00
2021-08-03T10:15:11.107899+00:00
624
false
**O(logn) Binary Search Solution:**\nExplanation:\nFor a regular sorted array where each element is double, be have the first in an even index and the second in an odd index.\nIf somewhere in the middle we have an element that appears only once, this pattern will be broken, and from there on the first element will be i...
10
0
['C']
1
single-element-in-a-sorted-array
Find the Single Element in a Sorted Array (Binary Search) #EfficientAlgorithms
find-the-single-element-in-a-sorted-arra-uuzi
Intuition The array is sorted, and every element appears exactly twice — except one. In such arrays, duplicates always occupy even-odd index pairs: (0-1), (2-3)
anill056
NORMAL
2025-03-26T19:51:06.194740+00:00
2025-03-26T19:51:06.194740+00:00
542
false
# Intuition - The array is sorted, and every element appears exactly twice — except one. - In such arrays, **duplicates always occupy even-odd index pairs**: (0-1), (2-3), etc. - When a single non-duplicate disrupts this structure, **the pattern breaks**. - So we can use binary search to find **where this break happens...
9
0
['Array', 'Binary Search', 'Bit Manipulation', 'C++']
1
single-element-in-a-sorted-array
Easy in C++😎 ||Binary Search|| (21st Feb 2023)
easy-in-c-binary-search-21st-feb-2023-by-utch
A good solution here would work even if the elements were not sorted, but just kept in pairs and that is because the searching criterium we will use is not rel
spyder_master
NORMAL
2023-02-21T04:02:14.609140+00:00
2023-02-21T04:02:14.609187+00:00
1,280
false
*A good solution here would work even if the elements were not sorted, but just kept in pairs and that is because the searching criterium we will use is not related to their own ordering, but to the fact that numbers to the left of the unique element will have the format nums[k] == nums[k + 1] with k being an even ind...
9
0
['C', 'Binary Tree', 'C++']
1
single-element-in-a-sorted-array
Easy C++ O(log n) & O(1) soln.
easy-c-olog-n-o1-soln-by-hirakmondal2000-vzfx
for (mid % 2 == 0) cases \n 0 1 2 3 4 5 6 7 8 -> index \n 1 1 2 2 3 5 5 7 7 - ON MID \n\t1 1 3 5 5 7 7 9 9 - ON LEFT
hirakmondal2000
NORMAL
2022-02-15T20:26:35.617260+00:00
2022-02-15T20:30:26.454661+00:00
180
false
for (mid % 2 == 0) cases \n 0 1 2 3 4 5 6 7 8 -> index \n 1 1 2 2 **3** 5 5 7 7 - ON MID \n\t1 1 **3** 5 5 7 7 9 9 - ON LEFT \n\t1 1 2 2 3 3 **5** 7 7 - ON RIGHT \n\t\nFor (mid % 2 != 0) cases \n0 1 2 3 4 5 6 -> index\n1 1 2 2 **3** 5 5 - ON RIGHT\n1 1 **3** 5 5 7 7 - ON L...
9
0
[]
1
single-element-in-a-sorted-array
🔥 [LeetCode The Hard Way] 🔥 Explained Line By Line
leetcode-the-hard-way-explained-line-by-0n5uy
\uD83D\uDD34 Check out LeetCode The Hard Way for more solution explanations and tutorials. \n\uD83D\uDFE0 Check out our Discord Study Group for live discussion.
__wkw__
NORMAL
2023-02-21T02:48:08.309133+00:00
2023-02-21T07:09:53.531577+00:00
1,258
false
\uD83D\uDD34 Check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. \n\uD83D\uDFE0 Check out our [Discord Study Group](https://discord.gg/Nqm4jJcyBf) for live discussion.\n\uD83D\uDFE2 Give a star on [Github Repository](https://github.com/wing...
8
0
['Binary Search', 'Python']
4
single-element-in-a-sorted-array
Deep Explanation | Leetcode Official Solution | Visual | [Python]
deep-explanation-leetcode-official-solut-vbdn
Overview \n\nWe must find the only unique element in a sorted array where all two copies of all other elements exist (or duplicate) \n \nfirst let us make some
gtshepard
NORMAL
2021-01-15T04:20:01.445192+00:00
2021-01-18T02:02:16.246563+00:00
288
false
### Overview \n\nWe must find the ***only unique*** element in a ***sorted array*** where all **two copies*** of all other elements exist (or duplicate) \n \nfirst let us make some key observtions about the problem \n\nassuming the constraints of the problem hold true, if there is a match for an element it always exi...
8
1
['Binary Tree']
0
single-element-in-a-sorted-array
Simple Solution with Diagrams in Video - JavaScript, C++, Java, Python
simple-solution-with-diagrams-in-video-j-nrg2
Video\nPlease upvote here so others save time too!\n\nLike the video on YouTube if you found it useful\n\nClick here to subscribe on YouTube:\nhttps://www.youtu
danieloi
NORMAL
2024-11-11T11:52:15.802768+00:00
2024-11-11T11:52:15.802805+00:00
625
false
# Video\nPlease upvote here so others save time too!\n\nLike the video on YouTube if you found it useful\n\nClick here to subscribe on YouTube:\nhttps://www.youtube.com/@mayowadan?sub_confirmation=1\n\nThanks!\n\nhttps://youtu.be/WHC5muNp2NQ?si=VHyNJgx7J1kZXjD_\n\n\n```Javascript []\n/**\n * @param {number[]} nums\n * ...
7
0
['Python', 'C++', 'Java', 'Python3', 'JavaScript']
0
single-element-in-a-sorted-array
Simple Binary Search Approach
simple-binary-search-approach-by-hemants-4838
Basic Idea: Find the number of element to the right of nums[m], and reduce search space according to it.\n\nclass Solution {\npublic:\n int singleNonDuplicat
hemantsingh_here
NORMAL
2024-07-22T18:29:48.553887+00:00
2024-07-22T18:29:48.553920+00:00
1,881
false
**Basic Idea:** Find the number of element to the right of nums[m], and reduce search space according to it.\n```\nclass Solution {\npublic:\n int singleNonDuplicate(vector<int>& nums) {\n \n int l = 0;\n int h = nums.size() - 1;\n \n \n while(l<h){\n int m = l +...
7
0
['Math', 'Binary Tree']
0
single-element-in-a-sorted-array
Beats 100% Java Solutions
beats-100-java-solutions-by-atharvakote8-wkix
Code Explanation\n\njava\npublic int singleNonDuplicate(int[] nums) {\n int low = 0;\n int high = nums.length - 1;\n\n while (low < high) {\n in
AtharvaKote81
NORMAL
2024-06-17T08:51:06.337549+00:00
2024-06-17T08:51:06.337580+00:00
191
false
## Code Explanation\n\n```java\npublic int singleNonDuplicate(int[] nums) {\n int low = 0;\n int high = nums.length - 1;\n\n while (low < high) {\n int mid = low + (high - low) / 2;\n if (mid % 2 == 1) {\n mid--;\n }\n\n if (nums[mid] == nums[mid + 1]) {\n low ...
7
0
[]
0
single-element-in-a-sorted-array
HashMap || Bitwise XOR ||Easy to understand || Java 2 Solutions
hashmap-bitwise-xor-easy-to-understand-j-pq00
Approach\n Describe your approach to solving the problem. \nApproach 1: Bit manupulation - TC O(n) - SC (1)\nHere we use the fact that performing XOR with two s
SidSai
NORMAL
2023-02-21T05:25:37.796896+00:00
2023-02-21T05:25:37.796936+00:00
92
false
# Approach\n<!-- Describe your approach to solving the problem. -->\n**Approach 1**: Bit manupulation - TC O(n) - SC (1)\nHere we use the fact that performing XOR with two same numbers give us zero and doing XOR with zero and other number will give us that number itself.\nhere\'s the example\n2 - 0010\n2 - 0010\n3 - 00...
7
0
['Java']
1
single-element-in-a-sorted-array
🅰️ Java | easy explained | two approach
a-java-easy-explained-two-approach-by-ha-og9u
\n# Approach 1\n Describe your approach to solving the problem. \nSo, Here we go what about the problem think carefully The first solution for this problem that
harshitisback
NORMAL
2023-02-21T05:14:06.820920+00:00
2023-02-21T05:14:38.912859+00:00
379
false
\n# Approach 1\n<!-- Describe your approach to solving the problem. -->\nSo, Here we go what about the problem think carefully The first solution for this problem that get accepted. what i did i just run a for loop with starting index of 1 and check for its previous one and with incremental value is +2 here we go. \n1....
7
0
['Java']
2
single-element-in-a-sorted-array
✅Python3 two approaches 🔥🔥
python3-two-approaches-by-shivam_1110-eki3
Intuition\n Describe your first thoughts on how to solve this problem. \nUsing xor approach and binary search we can solve this.\n\n# Approach 1: XOR 170ms\n De
shivam_1110
NORMAL
2023-02-21T04:28:43.272560+00:00
2023-02-21T04:37:08.037420+00:00
913
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n**Using xor approach and binary search we can solve this.**\n\n# Approach 1: XOR 170ms\n<!-- Describe your approach to solving the problem. -->\n- traverse in array linearly and xor every element.\n- which ever element is not repeted it\'...
7
0
['Array', 'Binary Search', 'Python3']
0
single-element-in-a-sorted-array
Simple C++ code || Approach discussed || TC : O(logN) & SC : O(1) || Binary search
simple-c-code-approach-discussed-tc-olog-tbhq
\n\n\n\n\n// Please upvote if it helps :)\n\nclass Solution {\npublic:\n int singleNonDuplicate(vector<int>& nums) {\n int e = nums.size();\n /
chamoli2k2
NORMAL
2022-07-22T23:31:17.705296+00:00
2022-07-23T15:49:35.142167+00:00
447
false
![image](https://assets.leetcode.com/users/images/3fd1b723-c888-4af7-9e8e-8d09f071871e_1658591320.434945.jpeg)\n\n\n```\n\n// Please upvote if it helps :)\n\nclass Solution {\npublic:\n int singleNonDuplicate(vector<int>& nums) {\n int e = nums.size();\n // Checking the boundary first\n if(e == ...
7
0
['Binary Search', 'C', 'Python', 'C++']
0
single-element-in-a-sorted-array
O(logN) time , O(1) space , easy to understand.
ologn-time-o1-space-easy-to-understand-b-esan
\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int low=0;\n int high=nums.length;\n while(low<=high){\n i
nandini29110
NORMAL
2022-01-17T07:56:08.681092+00:00
2022-01-25T18:20:59.961266+00:00
258
false
```\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int low=0;\n int high=nums.length;\n while(low<=high){\n int mid=low+(high-low)/2;\n if(mid-1>=0 && nums[mid]==nums[mid-1]){\n // this is second occurance\n if(mid%2==1){\n ...
7
0
[]
0
single-element-in-a-sorted-array
C++ Two Simple and Clean Solutions, O(logn) / O(n), With Explanation
c-two-simple-and-clean-solutions-ologn-o-tso3
O(logn) Binary Search Solution:\nExplanation:\nFor a regular sorted array where each element is double, be have the first in an even index and the second in an
yehudisk
NORMAL
2021-11-20T17:10:46.495838+00:00
2021-11-20T17:10:46.495870+00:00
270
false
**O(logn) Binary Search Solution:**\nExplanation:\nFor a regular sorted array where each element is double, be have the first in an even index and the second in an odd index.\nIf somewhere in the middle we have an element that appears only once, this pattern will be broken, and from there on the first element will be i...
7
0
['C']
0
single-element-in-a-sorted-array
You Will Never Forget this Approach || Handwritten Dry Run
you-will-never-forget-this-approach-hand-fz6b
Please Upvote,it helps a lot to write Such Posts\n\n\n//////////////////////////////////////////////////////////////////////////////////////////////////////////
ayushdevrani
NORMAL
2021-11-20T14:02:15.423049+00:00
2021-11-20T14:12:13.678208+00:00
568
false
**Please Upvote,it helps a lot to write Such Posts**\n\n![image](https://assets.leetcode.com/users/images/67a81016-0023-44fd-bbc9-abdd4cec9d79_1637416896.3717594.jpeg)\n/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////\n![image]...
7
0
['Binary Search', 'Binary Tree', 'Java']
0
single-element-in-a-sorted-array
C++ Binary Search Solution O(LogN)
c-binary-search-solution-ologn-by-ahsan8-terw
Runtime: 4 ms, faster than 97.93% of C++ online submissions for Single Element in a Sorted Array.\nMemory Usage: 11.1 MB, less than 39.06% of C++ online submiss
ahsan83
NORMAL
2021-07-17T18:17:51.571437+00:00
2021-07-17T18:48:36.735035+00:00
609
false
Runtime: 4 ms, faster than 97.93% of C++ online submissions for Single Element in a Sorted Array.\nMemory Usage: 11.1 MB, less than 39.06% of C++ online submissions for Single Element in a Sorted Array.\n\n```\nWe can do binary search over the sorted array to find the single element. But on which condition we should\nm...
7
2
['Array', 'C', 'Binary Tree']
2
single-element-in-a-sorted-array
Short Javascript Binary Search Solution
short-javascript-binary-search-solution-3re9i
\nvar singleNonDuplicate = function(nums) {\n if (nums.length == 1) return nums[0];\n return bsa(0, nums.length - 1);\n function bsa(start, end) {\n
zaq258123
NORMAL
2020-05-12T09:25:58.750829+00:00
2020-05-19T02:36:24.844747+00:00
1,529
false
```\nvar singleNonDuplicate = function(nums) {\n if (nums.length == 1) return nums[0];\n return bsa(0, nums.length - 1);\n function bsa(start, end) {\n let mid = Math.floor((start + end) / 2);\n if (nums[mid] == nums[mid - 1]) return mid % 2 ? bsa(mid + 1, end) : bsa(start, mid);\n if (num...
7
0
['Binary Tree', 'JavaScript']
1
single-element-in-a-sorted-array
C++ 100% Beats.
c-100-beats-by-ramudarsingh46-bpsi
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
ramudarsingh46
NORMAL
2024-08-16T09:55:37.733718+00:00
2024-08-16T09:55:37.733762+00:00
31
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
6
0
['C++']
0
single-element-in-a-sorted-array
Java beats 100%
java-beats-100-by-deleted_user-3yaz
Java beats 100%\n\n\n\n# Code\n\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int left = 0, right = nums.length - 1;\n whil
deleted_user
NORMAL
2024-05-11T06:22:18.351645+00:00
2024-05-11T06:22:18.351677+00:00
50
false
Java beats 100%\n![image.png](https://assets.leetcode.com/users/images/32197143-98e9-480a-bfa5-dc0a52260b56_1715408532.546289.png)\n\n\n# Code\n```\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int left = 0, right = nums.length - 1;\n while (left < right) {\n int mid = (l...
6
0
['Java']
0
single-element-in-a-sorted-array
PuTtA EaSY Solution C++ ✅ | Beats 96% 🔥🔥 Binary Search |
putta-easy-solution-c-beats-96-binary-se-jvx8
Intuition\n Describe your first thoughts on how to solve this problem. \nBinary Search\n\n\n# Complexity\n- Time complexity:O(logn)\n Add your time complexity h
Saisreeramputta
NORMAL
2023-02-21T07:44:02.959868+00:00
2023-02-21T07:44:02.959915+00:00
3,503
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBinary Search\n\n\n# Complexity\n- Time complexity:$$O(logn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\...
6
0
['Binary Search', 'C++']
1
single-element-in-a-sorted-array
📌📌Python3 || ⚡166 ms, faster than 95.30% of Python3
python3-166-ms-faster-than-9530-of-pytho-tv18
\n\n\nclass Solution:\n def singleNonDuplicate(self, nums: List[int]) -> int:\n n = len(nums)\n start = 0\n end = n - 1\n \n
harshithdshetty
NORMAL
2023-02-21T00:07:38.854761+00:00
2023-02-21T00:08:51.833300+00:00
1,412
false
![image](https://assets.leetcode.com/users/images/efc9658c-14ab-4771-b4c6-9ca50950ec75_1676938125.9127867.png)\n\n```\nclass Solution:\n def singleNonDuplicate(self, nums: List[int]) -> int:\n n = len(nums)\n start = 0\n end = n - 1\n \n while start <= end:\n mid = start...
6
0
['Binary Search', 'Binary Tree', 'Python', 'Python3']
1
single-element-in-a-sorted-array
✔️ Straightforward Approach Using Binary Search, With Comments
straightforward-approach-using-binary-se-1ci4
Thumbs up if you find this helpful \uD83D\uDC4D\n\nThe idea of this solution is the following:\n\nSuppose we have the following array: [1,1,2,2,3,3,4,4,6,8,8]\n
keperkjr
NORMAL
2021-11-20T05:16:22.202533+00:00
2022-04-27T05:05:20.824487+00:00
135
false
**Thumbs up if you find this helpful** \uD83D\uDC4D\n\nThe idea of this solution is the following:\n\nSuppose we have the following array: ```[1,1,2,2,3,3,4,4,6,8,8]```\n\nWe can observe that for each pair: \n\n* The first pair element takes the even array index position \n* The second pair element takes the odd array ...
6
0
[]
0
single-element-in-a-sorted-array
one line python
one-line-python-by-fjp666-gd81
\nreturn sum(set(nums)) * 2 - sum(nums)\n
fjp666
NORMAL
2019-07-08T07:48:33.381574+00:00
2019-07-08T07:49:46.389698+00:00
670
false
```\nreturn sum(set(nums)) * 2 - sum(nums)\n```
6
2
['Python3']
4
single-element-in-a-sorted-array
Binary Search based approach in Python
binary-search-based-approach-in-python-b-i6z1
\nclass Solution(object):\n def singleNonDuplicate(self, list):\n low, high = 0 , len(list)-1\n while (low<high):\n mid = low + (hig
rudra_pratap
NORMAL
2017-04-20T20:12:25.953000+00:00
2018-08-24T08:14:27.975538+00:00
1,458
false
```\nclass Solution(object):\n def singleNonDuplicate(self, list):\n low, high = 0 , len(list)-1\n while (low<high):\n mid = low + (high-low)/2\n if (list[mid]!=list[mid+1] and list[mid]!=list[mid-1]):\n return list[mid]\n elif (mid%2 ==1 and list[mid]==l...
6
0
[]
0
single-element-in-a-sorted-array
Fundamental Binary Search Pattern
fundamental-binary-search-pattern-by-dix-jllp
\n# Code\njava []\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n\n int n = nums.length;\n\n if (n==1) return nums[0];\n
Dixon_N
NORMAL
2024-07-14T12:59:46.316724+00:00
2024-07-14T12:59:46.316748+00:00
1,318
false
\n# Code\n```java []\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n\n int n = nums.length;\n\n if (n==1) return nums[0];\n if(nums[0]!=nums[1]) return nums[0];\n if(nums[n-1]!=nums[n-2]) return nums[n-1];\n\n int low =1;\n int high = n-2;\n while (l...
5
0
['Java']
4
single-element-in-a-sorted-array
✅ 0 ms | simple java solution | 🚀100% faster
0-ms-simple-java-solution-100-faster-by-ctsfw
\n\n# Code\n\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n if(nums.length == 1) return nums[0];\n //create the search space
Sauravmehta
NORMAL
2023-02-21T16:19:55.317556+00:00
2023-02-21T16:19:55.317606+00:00
74
false
\n\n# Code\n```\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n if(nums.length == 1) return nums[0];\n //create the search space\n int low = 0;\n int high = nums.length-1;\n while(low <= high){\n //find the middle index;\n int mid = low+(high...
5
0
['Java']
0
single-element-in-a-sorted-array
JavaScript | 96% | O(log n) time | O(1) space | Binary Search
javascript-96-olog-n-time-o1-space-binar-wtxu
\n\n# Approach\n\n### Linear search\n\nA \bigoplus A = 0 (XOR-ing a number with itself always equals zero)\nA \bigoplus 0 = A (XOR-ing a number with zero always
costa73
NORMAL
2023-02-21T10:44:44.872535+00:00
2023-02-21T11:55:17.194864+00:00
911
false
![image.png](https://assets.leetcode.com/users/images/f5d988de-7e19-4e38-b41e-73a2b04cc022_1676972922.5721262.png)\n\n# Approach\n\n### Linear search\n\n$$A \\bigoplus A = 0$$ ($$XOR$$-ing a number with itself always equals zero)\n$$A \\bigoplus 0 = A$$ ($$XOR$$-ing a number with zero always equals original number)\n\n...
5
0
['Math', 'Binary Search', 'JavaScript']
0
single-element-in-a-sorted-array
✅C++✅3 Lines✅XOR Solution
c3-linesxor-solution-by-bhushan_mahajan-sj8n
\n# Approach\n- XOR of a number with itself results 0\n- XOR of a number with 0 results a number only\n- XOR of a number with itself, odd number of times result
Bhushan_Mahajan
NORMAL
2023-02-21T07:20:13.793953+00:00
2023-02-21T07:20:13.794012+00:00
293
false
\n# Approach\n- XOR of a number with itself results 0\n- XOR of a number with 0 results a number only\n- XOR of a number with itself, odd number of times results a number only\n- XOR of a number with itself, even number of times reuslts 0 \n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Code\n...
5
0
['C++']
0
single-element-in-a-sorted-array
✅ JAVA fastest solution
java-fastest-solution-by-coding_menance-yzqm
0ms runtime\n# JAVA Code\nJAVA []\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int left = 0, right = nums.length-1;\n whil
coding_menance
NORMAL
2023-02-21T06:32:46.994083+00:00
2023-02-21T06:32:46.994124+00:00
909
false
0ms runtime\n# JAVA Code\n``` JAVA []\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int left = 0, right = nums.length-1;\n while(left < right){\n int mid = (left + right)/2;\n if( (mid % 2 == 0 && nums[mid] == nums[mid +1]) || (mid %2 == 1 && nums[mid] == nums[...
5
0
['Java']
0
single-element-in-a-sorted-array
Using advantage of sorted array, Java o(n)
using-advantage-of-sorted-array-java-on-aapo6
\n# Approach\n Describe your approach to solving the problem. \nAs the given array is sorted, if the element is present twice,we can simply check by checking th
Kiruthick_Nvp
NORMAL
2023-02-21T02:58:25.680880+00:00
2023-03-07T01:49:47.207380+00:00
89
false
\n# Approach\n<!-- Describe your approach to solving the problem. -->\nAs the given array is sorted, if the element is present twice,we can simply check by checking the element with i+1 element, if twice the element found we can skip the next element, until the elements appearing twice we can search with i+=2, then if ...
5
0
['Java']
1
single-element-in-a-sorted-array
JAVA || 2 LINE CODE || HASHMAP
java-2-line-code-hashmap-by-sharforaz_ra-u180
PLEASE UPVOTE, IF YOU LIKE IT\n# Code\n\nclass Solution {\n public int singleNonDuplicate(int[] arr) {\n HashMap<Integer, Integer> map = new HashMap<>
sharforaz_rahman
NORMAL
2022-12-31T14:39:52.088134+00:00
2023-04-29T09:08:26.417214+00:00
486
false
**PLEASE** **UPVOTE**, **IF YOU LIKE IT**\n# Code\n```\nclass Solution {\n public int singleNonDuplicate(int[] arr) {\n HashMap<Integer, Integer> map = new HashMap<>();\n for (int i : arr) map.put(i, map.getOrDefault(i, 0) + 1);\n for (int i : arr) if (map.get(i) == 1) return i;\n return ...
5
0
['Hash Table', 'Hash Function', 'Java']
1
single-element-in-a-sorted-array
C++ | O(Log n) | O(1)
c-olog-n-o1-by-aastha30-o4w1
\n int singleNonDuplicate(vector<int>& nums) {\n int start = 0 , end = nums.size()-1;\n \n if(nums.size() == 1) return nums[0]; \n
Aastha30
NORMAL
2022-05-07T08:59:47.137465+00:00
2022-05-07T08:59:47.137493+00:00
185
false
```\n int singleNonDuplicate(vector<int>& nums) {\n int start = 0 , end = nums.size()-1;\n \n if(nums.size() == 1) return nums[0]; \n if(nums[0] != nums[1]) return nums[0];\n if(nums[end] != nums[end-1]) return nums[end];\n \n while(start<=end)\n {\n ...
5
0
['C', 'Binary Tree']
1
single-element-in-a-sorted-array
Easy java binary solution 100% faster
easy-java-binary-solution-100-faster-by-8ld7y
Please upvote if you find it helpful\n\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n if(nums.length==1){\n return nums[
debanamika
NORMAL
2022-02-14T07:35:12.445550+00:00
2022-02-14T07:35:12.445591+00:00
420
false
Please upvote if you find it helpful\n```\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n if(nums.length==1){\n return nums[0];\n }\n int l=0, h=nums.length-1;\n while(l<h){\n int mid = l + (h-l)/2;\n if(mid-1>=0 && nums[mid] == nums[mid-...
5
0
['Binary Search', 'Binary Tree', 'Java']
1
single-element-in-a-sorted-array
[JAVA] Binary Search || 100% fast || Each step explained with comments
java-binary-search-100-fast-each-step-ex-s49s
\'\'\'\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n \n // As we are given a sorted array + it says that our solution must
Shourya112001
NORMAL
2021-11-21T14:57:14.692601+00:00
2021-11-21T14:57:58.863980+00:00
309
false
\'\'\'\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n \n // As we are given a sorted array + it says that our solution must be of 0(log n) time\n // We, get the idea that we have to do BINARY SEARCH\n \n //BOUNDARY CONDITIONS:\n \n //1. Check if the...
5
0
['Binary Search', 'Binary Tree', 'Java']
0
single-element-in-a-sorted-array
Easy Java Solution | Faster than 100% | O(logN)
easy-java-solution-faster-than-100-ologn-bt1d
\npublic int singleNonDuplicate(int[] nums) {\n\tif(nums.length <= 2){\n\t\treturn nums[0];\n\t}\n\tint low = 0;\n\tint high = nums.length - 1;\n\tint mid;\n\tw
codelife148
NORMAL
2021-09-23T21:27:03.132416+00:00
2021-09-23T21:27:03.132446+00:00
444
false
```\npublic int singleNonDuplicate(int[] nums) {\n\tif(nums.length <= 2){\n\t\treturn nums[0];\n\t}\n\tint low = 0;\n\tint high = nums.length - 1;\n\tint mid;\n\twhile(low <= high){\n\t\tmid = low + (high - low) /2;\n\t\t\n\t\t//Check to see if element is in the middle\n\t\tif(mid > 0 && mid < nums.length - 1 && nums[m...
5
0
['Binary Tree', 'Java']
1
single-element-in-a-sorted-array
Java Binary Search, O(log n) solution
java-binary-search-olog-n-solution-by-ra-wfwk
\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int start = 0;\n int end = nums.length-1;\n \n if(nums.length
raj02
NORMAL
2021-08-31T15:07:49.144771+00:00
2021-08-31T15:07:49.144823+00:00
470
false
```\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int start = 0;\n int end = nums.length-1;\n \n if(nums.length == 0) return 0;\n else if(nums.length ==1) return nums[0];\n else if(nums[0] != nums[1]) return nums[0];\n else if(nums[end] != nums[end...
5
0
['Binary Search', 'Java']
0
single-element-in-a-sorted-array
0 ms sol using java (bit manipulation & binary search)
0-ms-sol-using-java-bit-manipulation-bin-kuwy
Bit manipulation\n\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int res = 0;\n for(int i=0;i<nums.length;i++)\n {\n
rmanish0308
NORMAL
2021-07-11T08:32:58.860820+00:00
2021-07-11T08:45:24.098783+00:00
220
false
Bit manipulation\n```\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int res = 0;\n for(int i=0;i<nums.length;i++)\n {\n res = res^nums[i];\n }\n return res;\n }\n}\n```\nbinary search\n```\nclass Solution {\n public int singleNonDuplicate(int[] ...
5
0
['Bit Manipulation', 'Binary Tree', 'Java']
0
single-element-in-a-sorted-array
[Figure] Use example as your guide: generalization
figure-use-example-as-your-guide-general-c766
\nIntuition:\nSorted array!\nThat suggests we can use binary search.\nThen I will use classical binary search template: [low_index, high_index)\nThe middle valu
codedayday
NORMAL
2020-05-12T16:41:49.101230+00:00
2020-05-12T22:37:21.257456+00:00
132
false
\n**Intuition:**\nSorted array!\nThat suggests we can use binary search.\nThen I will use classical binary search template: [low_index, high_index)\nThe middle value are highlighted in red color.\n\nThere is some observation about potential place for the unique item: it must be in an even-indexed position\n![image](htt...
5
1
[]
0
single-element-in-a-sorted-array
Python 3, today's one-liner
python-3-todays-one-liner-by-l1ne-qsfr
Method 1 - xor\n\nJust xor all the numbers together. You\'ll get the unique number. \n\nUse functools.reduce and operator.xor to do it one line.\n\nTime: O(n)\n
l1ne
NORMAL
2020-05-12T07:19:09.773636+00:00
2020-05-12T21:55:52.146543+00:00
272
false
# Method 1 - xor\n\nJust xor all the numbers together. You\'ll get the unique number. \n\nUse [functools.reduce](https://docs.python.org/3/library/functools.html#functools.reduce) and [operator.xor](https://docs.python.org/3/library/operator.html#operator.xor) to do it one line.\n\nTime: `O(n)`\nSpace: `O(1)`\n\n## One...
5
0
[]
4
single-element-in-a-sorted-array
[C++] Binary Search O(log N) | Use xor to maintain n and n+1 even, odd pair
c-binary-search-olog-n-use-xor-to-mainta-p3nt
\nint singleNonDuplicate(vector<int>& nums) {\n\tint start=0, end = nums.size()-1, mid;\n\twhile( start < end ) {\n\t\tmid = start + (end-start)/2;\n\t\tif( num
sonugiri
NORMAL
2020-05-03T21:21:13.775537+00:00
2020-05-05T05:17:48.026648+00:00
366
false
```\nint singleNonDuplicate(vector<int>& nums) {\n\tint start=0, end = nums.size()-1, mid;\n\twhile( start < end ) {\n\t\tmid = start + (end-start)/2;\n\t\tif( nums[mid] == nums[mid ^ 1] )\n\t\t\tstart = mid + 1;\n\t\telse\n\t\t\tend = mid;\n\t}\n\treturn nums[start];\n}\n```
5
0
['Binary Tree']
1
single-element-in-a-sorted-array
easy peasy python with lot of comments
easy-peasy-python-with-lot-of-comments-b-1mwr
\tdef singleNonDuplicate(self, nums: List[int]) -> int:\n ln = len(nums)\n if ln == 1:\n return nums[0]\n \n s, e = 0, ln
lostworld21
NORMAL
2019-09-02T00:50:08.096786+00:00
2019-09-02T00:50:08.096831+00:00
1,234
false
\tdef singleNonDuplicate(self, nums: List[int]) -> int:\n ln = len(nums)\n if ln == 1:\n return nums[0]\n \n s, e = 0, ln-1\n while s <= e:\n mid = (e-s)//2 + s\n # print(s, e, mid)\n if (mid == 0 or nums[mid-1] != nums[mid]) and (mid == ln-...
5
0
['Binary Search', 'Binary Tree', 'Python', 'Python3']
0
single-element-in-a-sorted-array
Python binary search O(logn)
python-binary-search-ologn-by-doqin-8xdo
\nclass Solution(object):\n def singleNonDuplicate(self, nums):\n """\n :type nums: List[int]\n :rtype: int\n """\n if len
doqin
NORMAL
2018-10-30T02:14:32.144404+00:00
2018-10-30T02:14:32.144444+00:00
1,808
false
```\nclass Solution(object):\n def singleNonDuplicate(self, nums):\n """\n :type nums: List[int]\n :rtype: int\n """\n if len(nums) < 1:\n return None\n l, r = 0, len(nums)-1\n while l < r:\n m = l + (r - l)/2\n if m - 1 < l or m + 1 >...
5
0
[]
2
single-element-in-a-sorted-array
Beats 100% || Binary Search || O(log n)
beats-100-binary-search-olog-n-by-aditya-13ot
Explanation: We perform a binary search to find the single non-duplicate element. If mid is even: If nums[mid] == nums[mid + 1], the unique element must be on t
Aditya_4444
NORMAL
2025-01-29T06:24:32.927763+00:00
2025-01-29T06:24:32.927763+00:00
437
false
Explanation: We perform a binary search to find the single non-duplicate element. If mid is even: If nums[mid] == nums[mid + 1], the unique element must be on the right, so we move l = mid + 2. Otherwise, we move r = mid. If mid is odd: If nums[mid] == nums[mid - 1], the unique element must be on the right, so we move ...
4
0
['Python3']
1
single-element-in-a-sorted-array
EASY TO C++ SOLUTION || 540. Single Element in a Sorted Array Solved Medium Topics
easy-to-c-solution-540-single-element-in-5xfh
IntuitionThe problem is based on the observation that in a sorted array where every element appears twice except for one, the position of elements can help us d
shivambit
NORMAL
2024-12-15T15:18:32.232826+00:00
2024-12-15T15:18:32.232826+00:00
358
false
# Intuition\n\nThe problem is based on the observation that in a sorted array where every element appears twice except for one, the position of elements can help us determine which half of the array to search. The key insight is that pairs of identical elements will always be positioned in such a way that their indices...
4
0
['Array', 'Binary Search', 'C++']
0
single-element-in-a-sorted-array
✅💯🔥Simple Code🚀📌|| 🔥✔️Easy to understand🎯 || 🎓🧠Beats 100%🔥|| Beginner friendly💀💯
simple-code-easy-to-understand-beats-100-sxy1
Solution tuntun mosi ki photo ke baad hai. Scroll Down\n\n# Code\njava []\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int i=0; i
atishayj4in
NORMAL
2024-08-20T21:02:16.112997+00:00
2024-08-20T21:02:16.113029+00:00
361
false
Solution tuntun mosi ki photo ke baad hai. Scroll Down\n![fd9d3417-20fb-4e19-98fa-3dd39eeedf43_1723794694.932518.png](https://assets.leetcode.com/users/images/a492c0ef-bde0-4447-81e6-2ded326cd877_1724187540.6168394.png)\n# Code\n```java []\nclass Solution {\n public int singleNonDuplicate(int[] nums) {\n int ...
4
1
['Array', 'Binary Search', 'C', 'Python', 'C++', 'Java', 'JavaScript']
0