string 4

[Python3] 문자열 뒤집기 reversed()

python에서 문자열을 뒤집는 방법은 여러 가지가 있습니다. reversed() 파이썬에서 기본적으로 제공하는 reversed 함수를 사용할 수 있습니다. 그러나 reversed 함수는 뒤집어진 문자열이 아닌 뒤집어진 iterator를 반환합니다. s = "apple pie" print(reversed(s)) # 출력 결과 : 따라서 반환받은 iterator를 join 함수를 통해 다시 문자열로 만들어야 합니다. join함수를 사용하여 길이가 0인 문자열 ''에 iterator를 추가하여 뒤집어진 문자열을 만들 수 있습니다. s = "apple pie" s_iter = reversed(s) print(''.join(s_iter)) # 출력 결과 : eip elppa 슬라이싱 reversed 함수 사용 ..

[GeeksforGeeks] Special array reversal

Special array reversal | Practice | GeeksforGeeks Given a string S, containing special characters and all the alphabets, reverse the string without affecting the positions of the special characters. Example 1: Input: S = "A&B" Output: "B&A" Explanation: As we i practice.geeksforgeeks.org 접근 Two pointer 를 활용해 문자 비교 및 변경 isalphabet() 함수를 활용 Python 문자열 내 두 문자를 스왑하는 함수가 따로 제공되지 않는다는 점 참고 솔루션 class S..

[LeetCode] 278. First Bad Version

https://leetcode.com/problems/first-bad-version/ 피봇을 사용하여 탐색하는 문제입니다. First Bad Version - LeetCode Can you solve this real interview question? First Bad Version - You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed base leetcode.com 솔루션 # The isBadVersion API is..

[LeetCode] 205. Isomorphic Strings

제 3의 문자열로 표현하여 문제를 해결할 수 있습니다. https://leetcode.com/problems/isomorphic-strings/ Isomorphic Strings - LeetCode Isomorphic Strings - Given two strings s and t, determine if they are isomorphic. Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving th leetcode.com 솔루션 class Solutio..