Skip to content

Commit c2073b2

Browse files
committed
leetcode basecode update, updated README
1 parent b041cbf commit c2073b2

27 files changed

+446
-390
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ A curated collection of competitive programming problems and solutions in Python
1414
python -m venv .venv
1515
```
1616

17-
Activate it:
17+
Activate on Windows:
18+
19+
```bash
20+
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUse
21+
.venv\Scripts\activate.ps1
22+
```
23+
24+
25+
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUse
1826

19-
| Platform | Command |
20-
|---|---|
21-
| Windows | `.venv\Scripts\activate` |
2227
| macOS / Linux | `source .venv/bin/activate` |
2328

2429
### 2. Install dependencies
@@ -97,3 +102,7 @@ Contributions are welcome! When adding a new solution, please ensure:
97102
1. The solution is placed in the appropriate platform folder.
98103
2. A corresponding unit test is included.
99104
3. All existing tests pass before submitting.
105+
106+
## Resources
107+
108+
* [Leetcode main](https://github.com/doocs/leetcode/tree/main)

src/app/leetcode/closest_binary_search_tree_value.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/app/leetcode/convert_sorted_list_to_binary_search_tree.py

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/app/leetcode/divide_two_integers.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/app/leetcode/edit_distance.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/app/leetcode/evaluate_reverse_polish_notation.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/app/leetcode/integer_to_roman.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/app/leetcode/intersection_of_two_arrays_ii.py

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Integer to Roman | https://leetcode.com/problems/integer-to-roman/
3+
"""
4+
5+
class IntegerToRoman:
6+
7+
def intToRoman(self, num: int) -> str:
8+
values = [1000, 900, 500, 400,
9+
100, 90, 50, 40,
10+
10, 9, 5, 4, 1]
11+
symbols = ["M", "CM", "D", "CD",
12+
"C", "XC", "L", "XL",
13+
"X", "IX", "V", "IV",
14+
"I"]
15+
roman = ''
16+
i = 0
17+
while num > 0:
18+
k = num / values[i]
19+
for j in range(k):
20+
roman += symbols[i]
21+
num -= values[i]
22+
i += 1
23+
return roman
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Divide two integers without using multiplication, division and mod operator. | https://leetcode.com/problems/divide-two-integers/
3+
"""
4+
5+
import math
6+
7+
class DivideTwoIntegers:
8+
MAX_INT = int(100000)
9+
10+
def divide(self, dividend, divisor):
11+
if divisor == 0:
12+
return self.MAX_INT
13+
if dividend == 0:
14+
return 0
15+
isPositive = (dividend < 0) == (divisor < 0)
16+
m = abs(dividend)
17+
n = abs(divisor)
18+
# ln and exp
19+
res = math.log(m) - math.log(n)
20+
res = int(math.exp(res))
21+
if isPositive:
22+
return min(res, 2147483647)
23+
return max(0 - res, -2147483648)

0 commit comments

Comments
 (0)