Skip to content

Commit 7d1ed56

Browse files
authored
Added tasks 50, 52, 69, 149
1 parent 48574da commit 7d1ed56

File tree

13 files changed

+248
-0
lines changed

13 files changed

+248
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
385385
| 0007 |[Reverse Integer](src/main/python/g0001_0100/s0007_reverse_integer/Solution0007.py)| Medium | Top_Interview_Questions, Math, Big_O_Time_O(log10(x))_Space_O(1) | 37 | 69.51
386386
| 0009 |[Palindrome Number](src/main/python/g0001_0100/s0009_palindrome_number/Solution0009.py)| Easy | Math, Big_O_Time_O(log10(x))_Space_O(1) | 4 | 80.28
387387
| 0172 |[Factorial Trailing Zeroes](src/main/python/g0101_0200/s0172_factorial_trailing_zeroes/Solution0172.py)| Medium | Top_Interview_Questions, Math | 0 | 100.00
388+
| 0050 |[Pow(x, n)](src/main/python/g0001_0100/s0050_powx_n/Solution0050.py)| Medium | Top_Interview_Questions, Math, Recursion | 0 | 100.00
388389

389390
#### Udemy Strings
390391

@@ -721,6 +722,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
721722
| 0077 |[Combinations](src/main/python/g0001_0100/s0077_combinations/Solution0077.py)| Medium | Backtracking | 91 | 95.48
722723
| 0046 |[Permutations](src/main/python/g0001_0100/s0046_permutations/Solution0046.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 0 | 100.00
723724
| 0039 |[Combination Sum](src/main/python/g0001_0100/s0039_combination_sum/Solution0039.py)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 4 | 90.51
725+
| 0052 |[N-Queens II](src/main/python/g0001_0100/s0052_n_queens_ii/Solution0052.py)| Hard | Backtracking | 3 | 96.02
724726
| 0022 |[Generate Parentheses](src/main/python/g0001_0100/s0022_generate_parentheses/Solution0022.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 0 | 100.00
725727
| 0079 |[Word Search](src/main/python/g0001_0100/s0079_word_search/Solution0079.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 623 | 94.85
726728

@@ -779,6 +781,9 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
779781
| 0009 |[Palindrome Number](src/main/python/g0001_0100/s0009_palindrome_number/Solution0009.py)| Easy | Math, Big_O_Time_O(log10(x))_Space_O(1) | 4 | 80.28
780782
| 0066 |[Plus One](src/main/python/g0001_0100/s0066_plus_one/Solution0066.py)| Easy | Top_Interview_Questions, Array, Math | 0 | 100.00
781783
| 0172 |[Factorial Trailing Zeroes](src/main/python/g0101_0200/s0172_factorial_trailing_zeroes/Solution0172.py)| Medium | Top_Interview_Questions, Math | 0 | 100.00
784+
| 0069 |[Sqrt(x)](src/main/python/g0001_0100/s0069_sqrtx/Solution0069.py)| Easy | Top_Interview_Questions, Math, Binary_Search | 0 | 100.00
785+
| 0050 |[Pow(x, n)](src/main/python/g0001_0100/s0050_powx_n/Solution0050.py)| Medium | Top_Interview_Questions, Math, Recursion | 0 | 100.00
786+
| 0149 |[Max Points on a Line](src/main/python/g0101_0200/s0149_max_points_on_a_line/Solution0149.py)| Hard | Top_Interview_Questions, Array, Hash_Table, Math, Geometry | 59 | 34.87
782787

783788
#### Top Interview 150 1D DP
784789

@@ -1254,6 +1259,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
12541259
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12551260
|-|-|-|-|-|-
12561261
| 0202 |[Happy Number](src/main/python/g0201_0300/s0202_happy_number/Solution0202.py)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 0 | 100.00
1262+
| 0149 |[Max Points on a Line](src/main/python/g0101_0200/s0149_max_points_on_a_line/Solution0149.py)| Hard | Top_Interview_Questions, Array, Hash_Table, Math, Geometry | 59 | 34.87
12571263

12581264
### Binary Search I
12591265

@@ -1277,6 +1283,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
12771283

12781284
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12791285
|-|-|-|-|-|-
1286+
| 0069 |[Sqrt(x)](src/main/python/g0001_0100/s0069_sqrtx/Solution0069.py)| Easy | Top_Interview_Questions, Math, Binary_Search | 0 | 100.00
12801287

12811288
#### Day 5
12821289

@@ -1826,6 +1833,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
18261833
| 0152 |[Maximum Product Subarray](src/main/python/g0101_0200/s0152_maximum_product_subarray/Solution0152.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Dynamic_Programming_I_Day_6, Level_2_Day_13_Dynamic_Programming, Udemy_Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 3 | 98.51
18271834
| 0151 |[Reverse Words in a String](src/main/python/g0101_0200/s0151_reverse_words_in_a_string/Solution0151.py)| Medium | String, Two_Pointers, LeetCode_75_Array/String, Udemy_Strings, Top_Interview_150_Array/String | 0 | 100.00
18281835
| 0150 |[Evaluate Reverse Polish Notation](src/main/python/g0101_0200/s0150_evaluate_reverse_polish_notation/Solution0150.py)| Medium | Top_Interview_Questions, Array, Math, Stack, Programming_Skills_II_Day_3, Top_Interview_150_Stack | 0 | 100.00
1836+
| 0149 |[Max Points on a Line](src/main/python/g0101_0200/s0149_max_points_on_a_line/Solution0149.py)| Hard | Top_Interview_Questions, Array, Hash_Table, Math, Geometry, Algorithm_II_Day_21_Others, Top_Interview_150_Math | 59 | 34.87
18291837
| 0148 |[Sort List](src/main/python/g0101_0200/s0148_sort_list/Solution0148.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Level_2_Day_4_Linked_List, Top_Interview_150_Divide_and_Conquer, Big_O_Time_O(log(N))_Space_O(log(N)) | 186 | 43.67
18301838
| 0146 |[LRU Cache](src/main/python/g0101_0200/s0146_lru_cache/LRUCache.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Udemy_Linked_List, Top_Interview_150_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 113 | 84.08
18311839
| 0142 |[Linked List Cycle II](src/main/python/g0101_0200/s0142_linked_list_cycle_ii/Solution0142.py)| Medium | Top_100_Liked_Questions, Hash_Table, Two_Pointers, Linked_List, Data_Structure_II_Day_10_Linked_List, Level_1_Day_4_Linked_List, Udemy_Linked_List, Big_O_Time_O(N)_Space_O(1) | 38 | 94.15
@@ -1879,6 +1887,7 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
18791887
| 0072 |[Edit Distance](src/main/python/g0001_0100/s0072_edit_distance/Solution0072.py)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, LeetCode_75_DP/Multidimensional, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming, Top_Interview_150_Multidimensional_DP, Big_O_Time_O(n^2)_Space_O(n2) | 23 | 98.84
18801888
| 0071 |[Simplify Path](src/main/python/g0001_0100/s0071_simplify_path/Solution0071.py)| Medium | String, Stack, Top_Interview_150_Stack | 0 | 100.00
18811889
| 0070 |[Climbing Stairs](src/main/python/g0001_0100/s0070_climbing_stairs/Solution0070.py)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Algorithm_I_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_2, Level_1_Day_10_Dynamic_Programming, Udemy_Dynamic_Programming, Top_Interview_150_1D_DP, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
1890+
| 0069 |[Sqrt(x)](src/main/python/g0001_0100/s0069_sqrtx/Solution0069.py)| Easy | Top_Interview_Questions, Math, Binary_Search, Binary_Search_I_Day_4, Top_Interview_150_Math | 0 | 100.00
18821891
| 0068 |[Text Justification](src/main/python/g0001_0100/s0068_text_justification/Solution0068.py)| Hard | Array, String, Simulation, Top_Interview_150_Array/String | 0 | 100.00
18831892
| 0067 |[Add Binary](src/main/python/g0001_0100/s0067_add_binary/Solution0067.py)| Easy | String, Math, Bit_Manipulation, Simulation, Programming_Skills_II_Day_5, Top_Interview_150_Bit_Manipulation | 0 | 100.00
18841893
| 0066 |[Plus One](src/main/python/g0001_0100/s0066_plus_one/Solution0066.py)| Easy | Top_Interview_Questions, Array, Math, Programming_Skills_II_Day_3, Udemy_Arrays, Top_Interview_150_Math | 0 | 100.00
@@ -1892,7 +1901,9 @@ Python-based LeetCode algorithm problem solutions, regularly updated.
18921901
| 0055 |[Jump Game](src/main/python/g0001_0100/s0055_jump_game/Solution0055.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Algorithm_II_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_4, Udemy_Arrays, Top_Interview_150_Array/String, Big_O_Time_O(n)_Space_O(1) | 12 | 85.38
18931902
| 0054 |[Spiral Matrix](src/main/python/g0001_0100/s0054_spiral_matrix/Solution0054.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Simulation, Programming_Skills_II_Day_8, Level_2_Day_1_Implementation/Simulation, Udemy_2D_Arrays/Matrix, Top_Interview_150_Matrix | 0 | 100.00
18941903
| 0053 |[Maximum Subarray](src/main/python/g0001_0100/s0053_maximum_subarray/Solution0053.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Data_Structure_I_Day_1_Array, Dynamic_Programming_I_Day_5, Udemy_Famous_Algorithm, Top_Interview_150_Kadane's_Algorithm, Big_O_Time_O(n)_Space_O(1) | 50 | 77.23
1904+
| 0052 |[N-Queens II](src/main/python/g0001_0100/s0052_n_queens_ii/Solution0052.py)| Hard | Backtracking, Top_Interview_150_Backtracking | 3 | 96.02
18951905
| 0051 |[N-Queens](src/main/python/g0001_0100/s0051_n_queens/Solution0051.py)| Hard | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(N!)_Space_O(N) | 6 | 98.12
1906+
| 0050 |[Pow(x, n)](src/main/python/g0001_0100/s0050_powx_n/Solution0050.py)| Medium | Top_Interview_Questions, Math, Recursion, Udemy_Integers, Top_Interview_150_Math | 0 | 100.00
18961907
| 0049 |[Group Anagrams](src/main/python/g0001_0100/s0049_group_anagrams/Solution0049.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Data_Structure_II_Day_8_String, Programming_Skills_II_Day_11, Udemy_Strings, Top_Interview_150_Hashmap, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 11 | 82.75
18971908
| 0048 |[Rotate Image](src/main/python/g0001_0100/s0048_rotate_image/Solution0048.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Data_Structure_II_Day_3_Array, Programming_Skills_II_Day_7, Udemy_2D_Arrays/Matrix, Top_Interview_150_Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00
18981909
| 0046 |[Permutations](src/main/python/g0001_0100/s0046_permutations/Solution0046.py)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Algorithm_I_Day_11_Recursion_Backtracking, Level_2_Day_20_Brute_Force/Backtracking, Udemy_Backtracking/Recursion, Top_Interview_150_Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 0 | 100.00
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# #Medium #Top_Interview_Questions #Math #Recursion #Udemy_Integers #Top_Interview_150_Math
2+
# #2025_09_20_Time_0_ms_(100.00%)_Space_17.80_MB_(50.14%)
3+
4+
class Solution:
5+
def myPow(self, x: float, n: int) -> float:
6+
nn = n
7+
res = 1.0
8+
if n < 0:
9+
nn = -nn
10+
while nn > 0:
11+
if nn % 2 == 1:
12+
nn -= 1
13+
res *= x
14+
else:
15+
x *= x
16+
nn //= 2
17+
if n < 0:
18+
return 1.0 / res
19+
return res
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from Solution0050 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_myPow(self):
6+
self.assertEqual(Solution().myPow(2.00000, 10), 1024.00000)
7+
8+
def test_myPow2(self):
9+
self.assertEqual(Solution().myPow(2.10000, 3), 9.261000000000001)
10+
11+
def test_myPow3(self):
12+
self.assertEqual(Solution().myPow(2.00000, -2), 0.25000)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
50\. Pow(x, n)
2+
3+
Medium
4+
5+
Implement [pow(x, n)](http://www.cplusplus.com/reference/valarray/pow/), which calculates `x` raised to the power `n` (i.e., <code>x<sup>n</sup></code>).
6+
7+
**Example 1:**
8+
9+
**Input:** x = 2.00000, n = 10
10+
11+
**Output:** 1024.00000
12+
13+
**Example 2:**
14+
15+
**Input:** x = 2.10000, n = 3
16+
17+
**Output:** 9.26100
18+
19+
**Example 3:**
20+
21+
**Input:** x = 2.00000, n = -2
22+
23+
**Output:** 0.25000
24+
25+
**Explanation:** 2<sup>\-2</sup> = 1/2<sup>2</sup> = 1/4 = 0.25
26+
27+
**Constraints:**
28+
29+
* `-100.0 < x < 100.0`
30+
* <code>-2<sup>31</sup> <= n <= 2<sup>31</sup>-1</code>
31+
* <code>-10<sup>4</sup> <= x<sup>n</sup> <= 10<sup>4</sup></code>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# #Hard #Backtracking #Top_Interview_150_Backtracking
2+
# #2025_09_20_Time_3_ms_(96.02%)_Space_17.86_MB_(43.80%)
3+
4+
class Solution:
5+
def totalNQueens(self, n: int) -> int:
6+
row = [False] * n
7+
col = [False] * n
8+
diagonal = [False] * (2 * n - 1)
9+
antiDiagonal = [False] * (2 * n - 1)
10+
return self._totalNQueens(n, 0, row, col, diagonal, antiDiagonal)
11+
12+
def _totalNQueens(self, n, r, row, col, diagonal, antiDiagonal):
13+
if r == n:
14+
return 1
15+
count = 0
16+
for c in range(n):
17+
if not row[r] and not col[c] and not diagonal[r + c] and not antiDiagonal[r - c + n - 1]:
18+
row[r] = col[c] = diagonal[r + c] = antiDiagonal[r - c + n - 1] = True
19+
count += self._totalNQueens(n, r + 1, row, col, diagonal, antiDiagonal)
20+
row[r] = col[c] = diagonal[r + c] = antiDiagonal[r - c + n - 1] = False
21+
return count
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import unittest
2+
from Solution0052 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_totalNQueens(self):
6+
self.assertEqual(Solution().totalNQueens(4), 2)
7+
8+
def test_totalNQueens2(self):
9+
self.assertEqual(Solution().totalNQueens(1), 1)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
52\. N-Queens II
2+
3+
Hard
4+
5+
The **n-queens** puzzle is the problem of placing `n` queens on an `n x n` chessboard such that no two queens attack each other.
6+
7+
Given an integer `n`, return _the number of distinct solutions to the **n-queens puzzle**_.
8+
9+
**Example 1:**
10+
11+
![](https://assets.leetcode.com/uploads/2020/11/13/queens.jpg)
12+
13+
**Input:** n = 4
14+
15+
**Output:** 2
16+
17+
**Explanation:** There are two distinct solutions to the 4-queens puzzle as shown.
18+
19+
**Example 2:**
20+
21+
**Input:** n = 1
22+
23+
**Output:** 1
24+
25+
**Constraints:**
26+
27+
* `1 <= n <= 9`
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# #Easy #Top_Interview_Questions #Math #Binary_Search #Binary_Search_I_Day_4
2+
# #Top_Interview_150_Math #2025_09_20_Time_0_ms_(100.00%)_Space_17.75_MB_(51.52%)
3+
4+
class Solution:
5+
def mySqrt(self, x: int) -> int:
6+
if x == 0:
7+
return 0
8+
left, right = 1, x
9+
while left <= right:
10+
mid = (left + right) // 2
11+
if mid * mid == x:
12+
return mid
13+
elif mid * mid < x:
14+
left = mid + 1
15+
else:
16+
right = mid - 1
17+
return right
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import unittest
2+
from Solution0069 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_mySqrt(self):
6+
self.assertEqual(Solution().mySqrt(4), 2)
7+
8+
def test_mySqrt2(self):
9+
self.assertEqual(Solution().mySqrt(8), 2)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
69\. Sqrt(x)
2+
3+
Easy
4+
5+
Given a non-negative integer `x`, compute and return _the square root of_ `x`.
6+
7+
Since the return type is an integer, the decimal digits are **truncated**, and only **the integer part** of the result is returned.
8+
9+
**Note:** You are not allowed to use any built-in exponent function or operator, such as `pow(x, 0.5)` or `x ** 0.5`.
10+
11+
**Example 1:**
12+
13+
**Input:** x = 4
14+
15+
**Output:** 2
16+
17+
**Example 2:**
18+
19+
**Input:** x = 8
20+
21+
**Output:** 2
22+
23+
**Explanation:** The square root of 8 is 2.82842..., and since the decimal part is truncated, 2 is returned.
24+
25+
**Constraints:**
26+
27+
* <code>0 <= x <= 2<sup>31</sup> - 1</code>

0 commit comments

Comments
 (0)