Skip to content

Commit c4f3587

Browse files
7/8/24
1 parent 7720c9f commit c4f3587

File tree

4 files changed

+110
-27
lines changed

4 files changed

+110
-27
lines changed

Diff for: 13_Roman to Integer/solution.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,35 @@
3939
s = "LII"
4040

4141
greeksymbols = {
42-
"I" : 1,
43-
"V" : 5,
44-
"X" : 10,
45-
"L" : 50
46-
}
42+
"I": 1,
43+
"V": 5,
44+
"X": 10,
45+
"L": 50
46+
}
4747

4848

49-
def RtoI(roman) -> int:
50-
listnumbers = [i for i in roman]
49+
def RtoI(s) -> int:
50+
listnumbers = [i for i in s]
5151
sum = 0
5252
pointer1, pointer2 = 0, 1
5353

54-
while pointer1 < (len(listnumbers) - 1):
54+
for i in range(len(s) - 1):
5555
current_val = greeksymbols[listnumbers[pointer1]]
5656
next_val = greeksymbols[listnumbers[pointer2]]
57-
if int(current_val) < int(next_val):
58-
sum -= int(next_val) - int(current_val)
59-
pointer1 += 2
60-
pointer2 += 2
57+
if current_val < next_val:
58+
sum -= current_val
59+
pointer1 += 1
60+
pointer2 += 1
6161
else:
62-
sum += int(current_val)
62+
sum += current_val
6363
pointer1 += 1
6464
pointer2 += 1
6565

66+
6667
if pointer1 == len(listnumbers) - 1:
6768
sum += greeksymbols[listnumbers[pointer1]]
6869

6970
return sum
7071

7172

72-
print(RtoI(s))
73+
print(RtoI(s))

Diff for: 392_Is Subsequence/solution.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,17 @@
1919

2020

2121
def check(s, t) -> bool:
22-
list1 = [i for i in s] # b b
22+
list1 = [i for i in s] # b g
2323
list2 = [i for i in t] # a h b g c d
2424

2525
po1, po2 = 0, 0
26-
stop = list2[-1]
2726

28-
if len(list1) == 0:
29-
return False
30-
31-
while po1 < len(list1):
27+
while po1 < len(s) and po2 < len(t):
3228
if list1[po1] == list2[po2]:
3329
po1 += 1
34-
35-
elif list2[po2] == stop:
36-
return False
3730
po2 += 1
3831

39-
return True
40-
41-
32+
return po1 == len(list1)
4233

4334

4435
print(check(s, t))

Diff for: 832_Flipping an Image/solution.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image.
2+
#
3+
# To flip an image horizontally means that each row of the image is reversed.
4+
#
5+
# For example, flipping [1,1,0] horizontally results in [0,1,1].
6+
# To invert an image means that each 0 is replaced by 1, and each 1 is replaced by 0.
7+
#
8+
# For example, inverting [0,1,1] results in [1,0,0].
9+
#
10+
#
11+
# Example 1:
12+
#
13+
# Input: image = [[1,1,0],[1,0,1],[0,0,0]]
14+
# Output: [[1,0,0],[0,1,0],[1,1,1]]
15+
# Explanation: First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].
16+
# Then, invert the image: [[1,0,0],[0,1,0],[1,1,1]]
17+
# Example 2:
18+
#
19+
# Input: image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]
20+
# Output: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
21+
# Explanation: First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]].
22+
# Then invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]
23+
24+
25+
image = [[1,1,0],[1,0,1],[0,0,0]]
26+
27+
def fliping_image(image):
28+
for i in image:
29+
i.reverse()
30+
return image
31+
32+
def invert_image(image):
33+
for i in range(len(image)):
34+
for j in range(len(image[i])):
35+
image[i][j] = 1 - image[i][j]
36+
37+
return image
38+
39+
40+
flip = fliping_image(image)
41+
42+
print(invert_image(flip))

Diff for: practice_small_code.ipynb

+50-1
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,62 @@
5454
],
5555
"execution_count": 6
5656
},
57+
{
58+
"metadata": {
59+
"ExecuteTime": {
60+
"end_time": "2024-08-07T16:57:33.442540Z",
61+
"start_time": "2024-08-07T16:57:33.438185Z"
62+
}
63+
},
64+
"cell_type": "code",
65+
"source": [
66+
"sum = 0\n",
67+
"sum -=100\n",
68+
"print(sum)"
69+
],
70+
"id": "282cf3c329427e88",
71+
"outputs": [
72+
{
73+
"name": "stdout",
74+
"output_type": "stream",
75+
"text": [
76+
"-100\n"
77+
]
78+
}
79+
],
80+
"execution_count": 7
81+
},
82+
{
83+
"metadata": {
84+
"ExecuteTime": {
85+
"end_time": "2024-08-07T17:27:28.052977Z",
86+
"start_time": "2024-08-07T17:27:28.048411Z"
87+
}
88+
},
89+
"cell_type": "code",
90+
"source": [
91+
"image = [[1,1,0],[1,0,1],[0,0,0]]\n",
92+
"print(len(image[1]))"
93+
],
94+
"id": "383ad78972533c49",
95+
"outputs": [
96+
{
97+
"name": "stdout",
98+
"output_type": "stream",
99+
"text": [
100+
"3\n"
101+
]
102+
}
103+
],
104+
"execution_count": 10
105+
},
57106
{
58107
"metadata": {},
59108
"cell_type": "code",
60109
"outputs": [],
61110
"execution_count": null,
62111
"source": "",
63-
"id": "282cf3c329427e88"
112+
"id": "3afd94d8f063bc04"
64113
}
65114
],
66115
"metadata": {

0 commit comments

Comments
 (0)