Skip to content

Commit dd58020

Browse files
14
1 parent edadc2e commit dd58020

File tree

3 files changed

+85
-11
lines changed

3 files changed

+85
-11
lines changed

14 Longest Common Prefix/solution.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,24 @@
1515
# Explanation: There is no common prefix among the input strings.
1616
#
1717
#
18-
strs = ["flower", "flow", "flight"]
18+
strs = ["flower", "flow", "floight"]
1919

2020

2121
# strs = ["dog","racecar","car"]
2222

2323
def longest(strs) -> str:
24-
str_answer = ''
24+
prefix = strs[0] #flower
25+
answer = ""
2526
po1 = 0
26-
lenght = len(strs)
27-
m = min(len(s) for s in strs)
2827

29-
while po1 < m:
30-
store = ''
31-
for i in strs:
32-
if strs[i][po1] != strs[0][po1]:
33-
break
34-
else:
35-
str_answer += strs[i][po1]
28+
for i in prefix:
29+
for j in range(1, len(strs)):
30+
if po1 >= len(strs[j]) or i != strs[j][po1]:
31+
return answer
32+
answer += i
3633
po1 += 1
3734

35+
return answer
36+
3837

3938
print(longest(strs))

66 Plus One/solution.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's.
2+
#
3+
# Increment the large integer by one and return the resulting array of digits.
4+
#
5+
#
6+
#
7+
# Example 1:
8+
#
9+
# Input: digits = [1,2,3]
10+
# Output: [1,2,4]
11+
# Explanation: The array represents the integer 123.
12+
# Incrementing by one gives 123 + 1 = 124.
13+
# Thus, the result should be [1,2,4].
14+
15+
digits = [9, 9, 9]
16+
17+
18+
def plusone(digits) -> []:
19+
# st = ""
20+
# for i in digits:
21+
# st += str(i)
22+
# answer = int(st) + 1
23+
# answer1 = [int(i) for i in str(answer)]
24+
# return answer1
25+
26+
digits.reverse()
27+
28+
one, i = 1, 0
29+
30+
while one:
31+
if i < len(digits):
32+
if digits[i] == 9:
33+
digits[i] = 0
34+
else:
35+
digits[i] += 1
36+
one = 0
37+
38+
else:
39+
digits.append(1)
40+
one = 0
41+
42+
i += 1
43+
44+
return digits[::-1]
45+
46+
print(plusone(digits))

practice_small_code.ipynb

+29
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,35 @@
126126
}
127127
],
128128
"execution_count": 1
129+
},
130+
{
131+
"metadata": {
132+
"ExecuteTime": {
133+
"end_time": "2024-09-05T01:04:48.778648Z",
134+
"start_time": "2024-09-05T01:04:48.771965Z"
135+
}
136+
},
137+
"cell_type": "code",
138+
"source": [
139+
"string = \"1231\"\n",
140+
"\n",
141+
"for i in string:\n",
142+
" print(i)"
143+
],
144+
"id": "4484b5192a9f57db",
145+
"outputs": [
146+
{
147+
"name": "stdout",
148+
"output_type": "stream",
149+
"text": [
150+
"1\n",
151+
"2\n",
152+
"3\n",
153+
"1\n"
154+
]
155+
}
156+
],
157+
"execution_count": 1
129158
}
130159
],
131160
"metadata": {

0 commit comments

Comments
 (0)