🌐 AI搜索 & 代理 主页
Skip to content

Commit e3697c2

Browse files
authored
Added tasks 240-416
1 parent 5649d70 commit e3697c2

File tree

21 files changed

+863
-0
lines changed

21 files changed

+863
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
5151

5252
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
5353
|-|-|-|-|-|-
54+
| 0240 |[Search a 2D Matrix II](src/main/c/g0201_0300/s0240_search_a_2d_matrix_ii/Solution.c)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 42 | 96.34
5455

5556
#### Day 5 Array
5657

@@ -144,6 +145,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
144145
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
145146
|-|-|-|-|-|-
146147
| 0215 |[Kth Largest Element in an Array](src/main/c/g0201_0300/s0215_kth_largest_element_in_an_array/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 0 | 100.00
148+
| 0347 |[Top K Frequent Elements](src/main/c/g0301_0400/s0347_top_k_frequent_elements/Solution.c)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Divide_and_Conquer, Quickselect, Bucket_Sort, Big_O_Time_O(n\*log(n))_Space_O(k) | 0 | 100.00
147149

148150
#### Day 21 Heap Priority Queue
149151

@@ -168,6 +170,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
168170

169171
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
170172
|-|-|-|-|-|-
173+
| 0283 |[Move Zeroes](src/main/c/g0201_0300/s0283_move_zeroes/Solution.c)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
171174

172175
#### Day 4 Two Pointers
173176

@@ -330,6 +333,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
330333

331334
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
332335
|-|-|-|-|-|-
336+
| 0300 |[Longest Increasing Subsequence](src/main/c/g0201_0300/s0300_longest_increasing_subsequence/Solution.c)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 0 | 100.00
333337

334338
#### Day 17 Dynamic Programming
335339

@@ -341,6 +345,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
341345
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
342346
|-|-|-|-|-|-
343347
| 0072 |[Edit Distance](src/main/c/g0001_0100/s0072_edit_distance/Solution.c)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 0 | 100.00
348+
| 0322 |[Coin Change](src/main/c/g0301_0400/s0322_coin_change/Solution.c)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 22 | 87.50
344349

345350
#### Day 19 Bit Manipulation
346351

@@ -440,6 +445,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
440445

441446
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
442447
|-|-|-|-|-|-
448+
| 0300 |[Longest Increasing Subsequence](src/main/c/g0201_0300/s0300_longest_increasing_subsequence/Solution.c)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 0 | 100.00
443449

444450
#### Day 4
445451

@@ -450,6 +456,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
450456

451457
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
452458
|-|-|-|-|-|-
459+
| 0287 |[Find the Duplicate Number](src/main/c/g0201_0300/s0287_find_the_duplicate_number/Solution.c)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Two_Pointers, Bit_Manipulation, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
453460

454461
#### Day 6
455462

@@ -465,6 +472,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
465472

466473
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
467474
|-|-|-|-|-|-
475+
| 0240 |[Search a 2D Matrix II](src/main/c/g0201_0300/s0240_search_a_2d_matrix_ii/Solution.c)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Big_O_Time_O(n+m)_Space_O(1) | 42 | 96.34
468476

469477
#### Day 9
470478

@@ -631,6 +639,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
631639

632640
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
633641
|-|-|-|-|-|-
642+
| 0300 |[Longest Increasing Subsequence](src/main/c/g0201_0300/s0300_longest_increasing_subsequence/Solution.c)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 0 | 100.00
634643

635644
#### Day 19
636645

@@ -642,6 +651,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
642651

643652
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
644653
|-|-|-|-|-|-
654+
| 0322 |[Coin Change](src/main/c/g0301_0400/s0322_coin_change/Solution.c)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 22 | 87.50
645655

646656
#### Day 21
647657

@@ -679,6 +689,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
679689

680690
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
681691
|-|-|-|-|-|-
692+
| 0283 |[Move Zeroes](src/main/c/g0201_0300/s0283_move_zeroes/Solution.c)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
682693

683694
#### Day 7 Array
684695

@@ -1024,6 +1035,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
10241035

10251036
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10261037
|-|-|-|-|-|-
1038+
| 0394 |[Decode String](src/main/c/g0301_0400/s0394_decode_string/Solution.c)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
10271039

10281040
#### Day 15 Heap
10291041

@@ -1099,11 +1111,13 @@ C-based LeetCode algorithm problem solutions, regularly updated.
10991111
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11001112
|-|-|-|-|-|-
11011113
| 0198 |[House Robber](src/main/c/g0101_0200/s0198_house_robber/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
1114+
| 0322 |[Coin Change](src/main/c/g0301_0400/s0322_coin_change/Solution.c)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Big_O_Time_O(m\*n)_Space_O(amount) | 22 | 87.50
11021115

11031116
#### Day 13 Dynamic Programming
11041117

11051118
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11061119
|-|-|-|-|-|-
1120+
| 0416 |[Partition Equal Subset Sum](src/main/c/g0401_0500/s0416_partition_equal_subset_sum/Solution.c)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Big_O_Time_O(n\*sums)_Space_O(n\*sums) | 47 | 78.26
11071121
| 0152 |[Maximum Product Subarray](src/main/c/g0101_0200/s0152_maximum_product_subarray/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
11081122

11091123
#### Day 14 Sliding Window/Two Pointer
@@ -1166,6 +1180,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
11661180
| 0003 |[Longest Substring Without Repeating Characters](src/main/c/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 15 | 29.93
11671181
| 0020 |[Valid Parentheses](src/main/c/g0001_0100/s0020_valid_parentheses/Solution.c)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
11681182
| 0005 |[Longest Palindromic Substring](src/main/c/g0001_0100/s0005_longest_palindromic_substring/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 2 | 97.74
1183+
| 0394 |[Decode String](src/main/c/g0301_0400/s0394_decode_string/Solution.c)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
11691184
| 0049 |[Group Anagrams](src/main/c/g0001_0100/s0049_group_anagrams/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 3 | 100.00
11701185

11711186
#### Udemy Binary Search
@@ -1180,6 +1195,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
11801195
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11811196
|-|-|-|-|-|-
11821197
| 0121 |[Best Time to Buy and Sell Stock](src/main/c/g0101_0200/s0121_best_time_to_buy_and_sell_stock/Solution.c)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
1198+
| 0283 |[Move Zeroes](src/main/c/g0201_0300/s0283_move_zeroes/Solution.c)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
11831199
| 0001 |[Two Sum](src/main/c/g0001_0100/s0001_two_sum/Solution.c)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 2 | 99.56
11841200
| 0189 |[Rotate Array](src/main/c/g0101_0200/s0189_rotate_array/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
11851201
| 0055 |[Jump Game](src/main/c/g0001_0100/s0055_jump_game/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
@@ -1265,6 +1281,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
12651281
| 0198 |[House Robber](src/main/c/g0101_0200/s0198_house_robber/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
12661282
| 0070 |[Climbing Stairs](src/main/c/g0001_0100/s0070_climbing_stairs/Solution.c)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 1 | 100.00
12671283
| 0064 |[Minimum Path Sum](src/main/c/g0001_0100/s0064_minimum_path_sum/Solution.c)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
1284+
| 0300 |[Longest Increasing Subsequence](src/main/c/g0201_0300/s0300_longest_increasing_subsequence/Solution.c)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Big_O_Time_O(n\*log_n)_Space_O(n) | 0 | 100.00
12681285
| 0072 |[Edit Distance](src/main/c/g0001_0100/s0072_edit_distance/Solution.c)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 0 | 100.00
12691286
| 0010 |[Regular Expression Matching](src/main/c/g0001_0100/s0010_regular_expression_matching/Solution.c)| Hard | Top_Interview_Questions, String, Dynamic_Programming, Recursion, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
12701287

@@ -1282,6 +1299,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
12821299

12831300
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12841301
|-|-|-|-|-|-
1302+
| 0338 |[Counting Bits](src/main/c/g0301_0400/s0338_counting_bits/Solution.c)| Easy | Dynamic_Programming, Bit_Manipulation, Big_O_Time_O(num)_Space_O(num) | 0 | 100.00
12851303

12861304
#### Udemy Design
12871305

@@ -1379,6 +1397,16 @@ C-based LeetCode algorithm problem solutions, regularly updated.
13791397

13801398
| # | Title | Difficulty | Tag | Time, ms | Time, %
13811399
|------|----------------|-------------|-------------|----------|---------
1400+
| 0416 |[Partition Equal Subset Sum](src/main/c/g0401_0500/s0416_partition_equal_subset_sum/Solution.c)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Level_2_Day_13_Dynamic_Programming, Big_O_Time_O(n\*sums)_Space_O(n\*sums) | 47 | 78.26
1401+
| 0394 |[Decode String](src/main/c/g0301_0400/s0394_decode_string/Solution.c)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Level_1_Day_14_Stack, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
1402+
| 0347 |[Top K Frequent Elements](src/main/c/g0301_0400/s0347_top_k_frequent_elements/Solution.c)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Divide_and_Conquer, Quickselect, Bucket_Sort, Data_Structure_II_Day_20_Heap_Priority_Queue, Big_O_Time_O(n\*log(n))_Space_O(k) | 0 | 100.00
1403+
| 0338 |[Counting Bits](src/main/c/g0301_0400/s0338_counting_bits/Solution.c)| Easy | Dynamic_Programming, Bit_Manipulation, Udemy_Bit_Manipulation, Big_O_Time_O(num)_Space_O(num) | 0 | 100.00
1404+
| 0322 |[Coin Change](src/main/c/g0301_0400/s0322_coin_change/Solution.c)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_20, Level_2_Day_12_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(amount) | 22 | 87.50
1405+
| 0300 |[Longest Increasing Subsequence](src/main/c/g0201_0300/s0300_longest_increasing_subsequence/Solution.c)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Algorithm_II_Day_16_Dynamic_Programming, Binary_Search_II_Day_3, Dynamic_Programming_I_Day_18, Udemy_Dynamic_Programming, Big_O_Time_O(n\*log_n)_Space_O(n) | 0 | 100.00
1406+
| 0295 |[Find Median from Data Stream](src/main/c/g0201_0300/s0295_find_median_from_data_stream/MedianFinder.c)| Hard | Top_100_Liked_Questions, Sorting, Two_Pointers, Design, Heap_Priority_Queue, Data_Stream, Big_O_Time_O(n\*log_n)_Space_O(n) | 28 | 100.00
1407+
| 0287 |[Find the Duplicate Number](src/main/c/g0201_0300/s0287_find_the_duplicate_number/Solution.c)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Two_Pointers, Bit_Manipulation, Binary_Search_II_Day_5, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
1408+
| 0283 |[Move Zeroes](src/main/c/g0201_0300/s0283_move_zeroes/Solution.c)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, Algorithm_I_Day_3_Two_Pointers, Programming_Skills_I_Day_6_Array, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
1409+
| 0240 |[Search a 2D Matrix II](src/main/c/g0201_0300/s0240_search_a_2d_matrix_ii/Solution.c)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Data_Structure_II_Day_4_Array, Binary_Search_II_Day_8, Big_O_Time_O(n+m)_Space_O(1) | 42 | 96.34
13821410
| 0239 |[Sliding Window Maximum](src/main/c/g0201_0300/s0239_sliding_window_maximum/Solution.c)| Hard | Top_100_Liked_Questions, Array, Heap_Priority_Queue, Sliding_Window, Queue, Monotonic_Queue, Udemy_Arrays, Big_O_Time_O(n\*k)_Space_O(n+k) | 4 | 95.24
13831411
| 0238 |[Product of Array Except Self](src/main/c/g0201_0300/s0238_product_of_array_except_self/Solution.c)| Medium | Top_100_Liked_Questions, Array, Prefix_Sum, Data_Structure_II_Day_5_Array, Udemy_Arrays, Big_O_Time_O(n^2)_Space_O(n) | 0 | 100.00
13841412
| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/c/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/Solution.c)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Data_Structure_II_Day_18_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(n)_Space_O(n) | 15 | 90.08
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Matrix #Divide_and_Conquer
2+
// #Data_Structure_II_Day_4_Array #Binary_Search_II_Day_8 #Big_O_Time_O(n+m)_Space_O(1)
3+
// #2024_11_07_Time_42_ms_(96.34%)_Space_11.9_MB_(56.70%)
4+
5+
#include <stdbool.h>
6+
#include <stdio.h>
7+
8+
bool searchMatrix(int** matrix, int matrixSize, int* matrixColSize, int target) {
9+
int r = 0;
10+
int c = matrixColSize[0] - 1; // Start from the top-right corner
11+
12+
while (r < matrixSize && c >= 0) {
13+
if (matrix[r][c] == target) {
14+
return true;
15+
} else if (matrix[r][c] > target) {
16+
c--; // Move left
17+
} else {
18+
r++; // Move down
19+
}
20+
}
21+
return false;
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
240\. Search a 2D Matrix II
2+
3+
Medium
4+
5+
Write an efficient algorithm that searches for a value `target` in an `m x n` integer matrix `matrix`. This matrix has the following properties:
6+
7+
* Integers in each row are sorted in ascending from left to right.
8+
* Integers in each column are sorted in ascending from top to bottom.
9+
10+
**Example 1:**
11+
12+
![](https://assets.leetcode.com/uploads/2020/11/24/searchgrid2.jpg)
13+
14+
**Input:** matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5
15+
16+
**Output:** true
17+
18+
**Example 2:**
19+
20+
![](https://assets.leetcode.com/uploads/2020/11/24/searchgrid.jpg)
21+
22+
**Input:** matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20
23+
24+
**Output:** false
25+
26+
**Constraints:**
27+
28+
* `m == matrix.length`
29+
* `n == matrix[i].length`
30+
* `1 <= n, m <= 300`
31+
* <code>-10<sup>9</sup> <= matrix[i][j] <= 10<sup>9</sup></code>
32+
* All the integers in each row are **sorted** in ascending order.
33+
* All the integers in each column are **sorted** in ascending order.
34+
* <code>-10<sup>9</sup> <= target <= 10<sup>9</sup></code>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// #Easy #Top_100_Liked_Questions #Array #Two_Pointers #Algorithm_I_Day_3_Two_Pointers
2+
// #Programming_Skills_I_Day_6_Array #Udemy_Arrays #Big_O_Time_O(n)_Space_O(1)
3+
// #2024_11_07_Time_0_ms_(100.00%)_Space_19.5_MB_(47.88%)
4+
5+
#include <stdio.h>
6+
7+
void swap(int* a, int* b) {
8+
int temp = *a;
9+
*a = *b;
10+
*b = temp;
11+
}
12+
13+
void moveZeroes(int* nums, int numsSize) {
14+
int firstZero = 0;
15+
for (int i = 0; i < numsSize; i++) {
16+
if (nums[i] != 0) {
17+
swap(&nums[firstZero], &nums[i]);
18+
firstZero++;
19+
}
20+
}
21+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
283\. Move Zeroes
2+
3+
Easy
4+
5+
Given an integer array `nums`, move all `0`'s to the end of it while maintaining the relative order of the non-zero elements.
6+
7+
**Note** that you must do this in-place without making a copy of the array.
8+
9+
**Example 1:**
10+
11+
**Input:** nums = [0,1,0,3,12]
12+
13+
**Output:** [1,3,12,0,0]
14+
15+
**Example 2:**
16+
17+
**Input:** nums = [0]
18+
19+
**Output:** [0]
20+
21+
**Constraints:**
22+
23+
* <code>1 <= nums.length <= 10<sup>4</sup></code>
24+
* <code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code>
25+
26+
**Follow up:** Could you minimize the total number of operations done?
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// #Medium #Top_100_Liked_Questions #Array #Binary_Search #Two_Pointers #Bit_Manipulation
2+
// #Binary_Search_II_Day_5 #Big_O_Time_O(n)_Space_O(n)
3+
// #2024_11_07_Time_0_ms_(100.00%)_Space_14_MB_(62.83%)
4+
5+
#include <stdio.h>
6+
7+
int findDuplicate(int* nums, int numsSize) {
8+
// Create an array of size numsSize + 1, initialized to 0
9+
int arr[numsSize + 1];
10+
for (int i = 0; i <= numsSize; i++) {
11+
arr[i] = 0;
12+
}
13+
14+
// Iterate over the nums array and update the arr counts
15+
for (int i = 0; i < numsSize; i++) {
16+
arr[nums[i]] += 1;
17+
if (arr[nums[i]] == 2) {
18+
return nums[i]; // Return the duplicate element
19+
}
20+
}
21+
22+
return 0; // In case no duplicate is found, though the problem assumes there is always a duplicate
23+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
287\. Find the Duplicate Number
2+
3+
Medium
4+
5+
Given an array of integers `nums` containing `n + 1` integers where each integer is in the range `[1, n]` inclusive.
6+
7+
There is only **one repeated number** in `nums`, return _this repeated number_.
8+
9+
You must solve the problem **without** modifying the array `nums` and uses only constant extra space.
10+
11+
**Example 1:**
12+
13+
**Input:** nums = [1,3,4,2,2]
14+
15+
**Output:** 2
16+
17+
**Example 2:**
18+
19+
**Input:** nums = [3,1,3,4,2]
20+
21+
**Output:** 3
22+
23+
**Constraints:**
24+
25+
* <code>1 <= n <= 10<sup>5</sup></code>
26+
* `nums.length == n + 1`
27+
* `1 <= nums[i] <= n`
28+
* All the integers in `nums` appear only **once** except for **precisely one integer** which appears **two or more** times.
29+
30+
**Follow up:**
31+
32+
* How can we prove that at least one duplicate number must exist in `nums`?
33+
* Can you solve the problem in linear runtime complexity?

0 commit comments

Comments
 (0)