Algorithm

문제 링크:https://leetcode.com/problems/valid-palindrome/description/?envType=study-plan-v2&envId=top-interview-150Palindrome 에 관한 문제이다. 문제만 잘 읽는다면 문제 없이 풀 수 있다.사실 leetcode를 풀 때 초반 장벽은 아마 영어 단어이지 않을까 싶다. 다행히 이 문제에서는 palindrome이 어떤 특징을 가진 단어인지 설명을 해주는데, 코테 문제에서는 설명을 안해주는 경우도 허다해서 난감했던 기억이 있다. [내 풀이]class Solution: def isPalindrome(self, s: str) -> bool: if len(s) == 0: return Tru..
다시 알고리즘 공부를 꾸준히 하기 위한 작심삼일 x 1년! 프로젝트를 시작했다. (작심삼일이라도 꾸준히 하자라는 마음가짐이다) 문제 링크:https://leetcode.com/problems/length-of-last-word/description/?envType=study-plan-v2&envId=top-interview-150 Easy 난이도인 만큼, 특히 python으로서는 아주 풀기 쉬운 문제였다. [내 풀이]class Solution: def lengthOfLastWord(self, s: str) -> int: word_list = s.strip().split() return len(word_list[-1]) 시간 복잡도where n is the length of ..
문제 링크: https://neetcode.io/problems/meeting-schedule NeetCode neetcode.io [내 풀이]"""Definition of Interval:class Interval(object): def __init__(self, start, end): self.start = start self.end = end"""class Solution: def canAttendMeetings(self, intervals: List[Interval]) -> bool: intervals.sort(key=lambda x: x.start) for i in range(len(intervals) - 1): ..
문제 링크: https://neetcode.io/problems/buy-and-sell-crypto NeetCode neetcode.io 투 포인터/슬라이딩 윈도우 [내 풀이]class Solution: def maxProfit(self, prices: List[int]) -> int: maxProfit = 0 for i in range(len(prices)-1): for j in range(i, len(prices)): profit = prices[j] - prices[i] if profit > maxProfit: maxProfit = profit ret..
빵빵0
'Algorithm' 카테고리의 글 목록