Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8c50795

Browse files
Merge pull requestneetcode-gh#2517 from Dhyan-P-Shetty/main
Create: 0402-remove-k-digits.py, Create: 1768-merge-strings-alternately.py
2 parents914ca1f +c9a443d commit8c50795

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

‎python/0402-remove-k-digits.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
classSolution:
2+
defremoveKdigits(self,num:str,k:int)->str:
3+
stack= []
4+
foriinnum:
5+
whilestackandstack[-1]>iandk>0:
6+
k-=1
7+
stack.pop()
8+
ifstackoriisnot"0":
9+
stack.append(i)
10+
ifk:
11+
stack=stack[:-k]
12+
return''.join(stack)or'0'
13+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
classSolution:
2+
defmergeAlternately(self,word1:str,word2:str)->str:
3+
i=j=0
4+
res= []
5+
6+
whilei<len(word1)andj<len(word2):
7+
res.append(word1[i])
8+
res.append(word2[j])
9+
i+=1
10+
j+=1
11+
res.append(word1[i:])
12+
res.append(word2[j:])
13+
return''.join(res)
14+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp