일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- Python
- 파이썬
- Python3
- 코드업
- 니트코드
- gcp
- 슬라이딩윈도우
- stratascratch
- SQL
- 투포인터
- 릿코드
- Microsoft
- 생성형AI
- 자연어처리
- LeetCode
- nlp
- 알고리즘
- heap
- sql코테
- slidingwindow
- GenerativeAI
- GenAI
- codeup
- 구글퀵랩
- dfs
- medium
- 파이썬기초100제
- 리트코드
- two-pointer
- 파이썬알고리즘
- Today
- Total
목록stringmanipulation (3)
Tech for good

https://neetcode.io/problems/is-palindrome NeetCode neetcode.io첫번째 방법 - String Manipulationclass Solution: def isPalindrome(self, s: str) -> bool: # 1. 알파벳과 숫자만 남기고 소문자로 변환 filtered_s = ''.join(c.lower() for c in s if c.isalnum()) # 2. 문자열을 뒤집어서 원래 문자열과 비교 return filtered_s == filtered_s[::-1]isalnum() -> 문자열이 문자 혹은 숫자로 되어있으면 참 리턴, 아니면 거짓 리턴시간 복잡도문자열 필터링: O..

1️⃣번째 방법class Solution: def reverseWords(self, s: str) -> str: return " ".join(s.split()[::-1]) 시간 복잡도 및 공간 복잡도시간 복잡도: O(n)split() → O(n)[::-1] (리스트 뒤집기) → O(n)" ".join() → O(n)따라서 전체 시간 복잡도는 O(n) 입니다.공간 복잡도: O(n)split()이 새로운 리스트를 생성하므로 O(n)의 추가 공간이 필요합니다.2️⃣번째 방법Follow-up: O(1) 추가 공간으로 해결할 수 있을까?문자열이 가변(mutable)한 경우, O(1) 공간에서 In-place 방식으로 해결할 수 있습니다.파이썬에서는 문자열이 **불변(immutable)**이라서 ..

class Solution: def isPrefixOfWord(self, sentence: str, searchWord: str) -> int: words = sentence.split() for i, word in enumerate(words): if word.startwith(searchword): return i+1 return -1Explanation:Split the Sentence: The input sentence is split into a list of words using .split(), which automatically handles single spaces.Iterate Over Words:..