Skip to content

Commit dce5aa9

Browse files
committed
leetcode - 344
1 parent e92eb77 commit dce5aa9

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

python/string/leetcode_344.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# LeetCode
2+
# 344. Reverse String
3+
# https://leetcode.com/problems/reverse-string/
4+
5+
def mySolution(s: [str]) -> None:
6+
# 그냥 뒤집는 방법
7+
s.reverse()
8+
9+
# 공간복잡도가 O(1)이기 때문에 해당 상황을 고려한 방벙
10+
s[:] = s[::-1]
11+
12+
def twoPointersSolution(s: [str]) -> None:
13+
# 투 포인터 사용
14+
left = 0
15+
right = len(s)-1
16+
17+
while left < right:
18+
s[left], s[right] = s[right], s[left]
19+
left += 1
20+
right -= 1

0 commit comments

Comments
 (0)