일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 머신러닝
- 빅데이터
- 릿코드
- 클라우드
- 코드업
- 코드업파이썬
- GenAI
- 생성형AI
- Python3
- 파이썬기초100제
- nlp
- 알고리즘
- 자연어처리
- 파이썬알고리즘
- 투포인터
- C#
- LeetCode
- 파이썬
- gcp
- Blazor
- Azure
- 구글퀵랩
- codeup
- Microsoft
- two-pointer
- Python
- 리트코드
- GenerativeAI
- 파이썬기초
- 데이터사이언스
- Today
- Total
목록문자열조작 (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:..