Skip to content

Commit 5b13ed0

Browse files
Merge branch 'CodeHarborHub:main' into leetcode30
2 parents f0dc5a6 + 5888b56 commit 5b13ed0

File tree

9 files changed

+154
-7
lines changed

9 files changed

+154
-7
lines changed
-16.1 KB
Loading
-28.7 KB
Loading
-20.6 KB
Loading

dsa-solutions/lc-solutions/0000-0099/0017-letter-combinations-of-a-phone-number.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,4 @@ Here's a step-by-step algorithm for generating all possible letter combinations
314314
- Call the backtracking function with the initial index set to 0 and an empty string as the initial combination.
315315
- Return the list of combinations.
316316

317-
This algorithm ensures that all possible combinations are generated by exploring all valid paths through backtracking.
317+
This algorithm ensures that all possible combinations are generated by exploring all valid paths through backtracking.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
id: single-number
3+
title: Single Number
4+
sidebar_label: 0136 Single Number
5+
tags:
6+
- Java
7+
- Python
8+
- C++
9+
- XOR
10+
description: "This is a solution to the Single Number problem on LeetCode."
11+
---
12+
13+
## Problem Description
14+
15+
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
16+
17+
You must implement a solution with a linear runtime complexity and use only constant extra space.
18+
19+
### Examples
20+
21+
**Example 1:**
22+
23+
```
24+
Input: nums = [2,2,1]
25+
Output: 1
26+
27+
```
28+
29+
**Example 2:**
30+
31+
Input: nums = [4,1,2,1,2]
32+
Output: 4
33+
34+
**Example 3:**
35+
36+
```
37+
Input: nums = [1]
38+
Output: 1
39+
```
40+
41+
### Constraints
42+
43+
- $1 \leq nums.length \leq 3 * 10^4$
44+
- $-3 \times 10^4 \leq nums[i] \leq 3 \times 10^4$
45+
- Each element in the array appears twice except for one element which appears only once.
46+
47+
---
48+
49+
## Solution for Single Number Problem
50+
51+
### Intuition
52+
53+
When faced with this problem, the first hurdle to overcome is the strict limitations imposed on the solution: linear time complexity and constant space complexity. This means traditional methods of identifying duplicates like hash tables or sorting won't cut it. Instead, we'll need to use a different kind of magic, one rooted in the world of bitwise operations!
54+
55+
### Approach
56+
57+
Our saviour here is the XOR operation. XOR stands for 'exclusive or', and the magic lies in its properties. When a number is XORed with itself, the result is 0. And when a number is XORed with 0, the result is the number itself.
58+
59+
So, if we XOR all the numbers in the array, all the numbers appearing twice will cancel each other out and we'll be left with the single number that appears only once.
60+
61+
#### Code in Different Languages
62+
63+
<Tabs>
64+
<TabItem value="Java" label="Java">
65+
<SolutionAuthor name="@vanAmsen"/>
66+
```java
67+
class Solution {
68+
public int singleNumber(int[] nums) {
69+
int result = 0;
70+
for (int num : nums) {
71+
result ^= num;
72+
}
73+
return result;
74+
}
75+
}
76+
77+
`````
78+
</TabItem>
79+
<TabItem value="Python" label="Python">
80+
<SolutionAuthor name="@vanAmsen"/>
81+
82+
````python
83+
class Solution:
84+
def singleNumber(self, nums: List[int]) -> int:
85+
result = 0
86+
for num in nums:
87+
result ^= num
88+
return result
89+
90+
`````
91+
92+
</TabItem>
93+
<TabItem value="C++" label="C++">
94+
<SolutionAuthor name="@vanAmsen"/>
95+
```cpp
96+
class Solution {
97+
public:
98+
int singleNumber(vector<int>& nums) {
99+
int result = 0;
100+
for (int num : nums) {
101+
result ^= num;
102+
}
103+
return result;
104+
}
105+
};
106+
107+
```
108+
</TabItem>
109+
</Tabs>
110+
111+
#### Complexity Analysis
112+
113+
- Time complexity: $O(n)$, as we're iterating over the array only once.
114+
- Space complexity: $O(1)$, because we're only using a single variable to store the result, irrespective of the size of the input.
115+
116+
## References
117+
118+
- **LeetCode Problem:** [Single Number](https://leetcode.com/problems/single-number/description/)
119+
- **Solution Link:** [Single NUmber on LeetCode](https://leetcode.com/problems/single-number/solutions/3801367/video-single-number-a-bitwise-magic-trick/)
120+
- **Authors Leetcode Profile:** [vanAmsen](https://leetcode.com/u/vanAmsen/)
121+
```

src/components/HomePage/style.css

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,23 @@
4444
}
4545

4646
.resources-section .resources-container .resources-filters {
47-
display: inline-flex;
48-
gap: 0.25rem;
49-
margin-bottom: 1.5rem;
47+
display: grid;
48+
grid-auto-flow: column;
49+
grid-auto-columns: max-content;
50+
gap: 10px;
51+
margin: 1.5rem 0;
5052
border-radius: 0.5rem;
5153
padding: 0.5rem;
5254
font-family: "Jakarta", sans-serif;
5355
font-size: 0.875rem;
54-
font-weight: 600;
56+
font-weight: 600;
57+
scroll-behavior: smooth;
58+
overflow-x: auto;
59+
white-space: nowrap;
60+
-ms-overflow-style: none;
61+
scrollbar-width: none;
62+
background-color: #07574e73;
63+
border: 1px solid #666;
5564
}
5665

5766
.bg-secondary-700 {
@@ -98,6 +107,8 @@
98107
.resource {
99108
text-decoration: none;
100109
color: inherit;
110+
border-radius: 0.5rem;
111+
box-shadow: 0 0 10px rgba(5, 174, 216, 0.386);
101112
}
102113

103114
.resources-section
@@ -155,6 +166,7 @@
155166
.resource-title {
156167
font-weight: 600;
157168
margin-bottom: 8px;
169+
padding: 0 0.5rem;
158170
}
159171

160172
.resources-section
@@ -163,6 +175,7 @@
163175
.resources-grid
164176
.resource-description {
165177
line-height: 1.375;
178+
padding: 0 0.5rem;
166179
}
167180

168181
.resources-section
@@ -180,13 +193,15 @@
180193
.resources-grid
181194
.resource-duration {
182195
font-size: 14px;
183-
color: #666;
196+
padding: 0.5rem;
197+
color: var(--ifm-color-primary);
184198
}
185199

186200
.resources-section .resources-container .pagination {
187201
display: flex;
188202
justify-content: center;
189203
gap: 1rem;
204+
margin-top: 2.5rem;
190205
}
191206

192207
.resources-section .resources-container .pagination .pagination-button {

src/data/showcase/captcha-code.png

60.3 KB
Loading

src/data/userData.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,15 @@ export const Users: User[] = [
128128
source: "https://github.com/ParnaRoyChowdhury777/ScanMe",
129129
tags: ["opensource", "product", "html", "css", "javascript", "vanilla"],
130130
},
131+
{
132+
title: "Captcha-Code Generator",
133+
description:
134+
"It generates a Captcha code based on the user's input and validates the user's input with the generated Captcha code.",
135+
preview: require("./showcase/captcha-code.png"),
136+
website:
137+
"https://50-days-50-web-project.vercel.app/captcha/captcha.html",
138+
source:
139+
"https://github.com/dhairyagothi/50_days_50_web_project/tree/Main/public/captcha",
140+
tags: ["html", "css", "javascript"],
141+
},
131142
];

0 commit comments

Comments
 (0)