| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
| 31 |
- 코딩테스트
- Data_Structure
- CNN
- 데이터
- 티스토리챌린지
- Python
- 대학생
- GNN
- 컴퓨터사이언스
- 컴퓨터공학
- meshgraphnet
- mysql
- 데이터베이스
- LeetCode
- Leet Code
- 데베
- 코테
- adaptive remeshing
- DS
- 개발자
- CS
- SQL
- sort
- db
- 자료구조
- 오블완
- code
- Mesh
- coding
- Database
- Today
- Total
목록LeetCode (11)
sy1214ei 님의 블로그
https://leetcode.com/problems/first-missing-positive/Level : Hardclass Solution: def firstMissingPositive(self, nums: List[int]) -> int: # 1. 음수는 0으로 for i in range(len(nums)): if nums[i] 0: nums[val-1] *= -1 elif nums[val-1] == 0: nums[val-1] = -1 * (len(nums)+1) # 3. 제일 작은 양수 찾기 for i in..
level : EasyTopics : Linked List | Recursionhttps://leetcode.com/problems/merge-two-sorted-lists/#Definition for singly-linked list.class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = nextclass Solution: def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]: dummy = ListNode() # 더미 노드 생성 ..
Level : EasyTopics : String https://leetcode.com/problems/length-of-last-word/description/Codeclass Solution: def lengthOfLastWord(self, s: str) -> int: # 1. str의 뒤 공백을 없애줍니다 # 2. str을 뒤에서 부터 돌면서 ' '이 나온다면 break # 3. return cnt s = list(s) for i in range(len(s)-1, -1, -1): if s[i] == ' ': s.pop(i) else: ..
class Solution: def dominantIndex(self, nums: List[int]) -> int: sorted_nums = sorted(nums) if sorted_nums[-1] >= sorted_nums[-2]*2: for i in range(len(nums)): if sorted_nums[-1] == nums[i]: return i else : return -1 # Time Complexity : O(n) # Space Complexity : O(n)
class Solution: def maximumProduct(self, nums: List[int]) -> int: nums = sorted(nums) return max(nums[0]*nums[1]*nums[-1],nums[-1]*nums[-2]*nums[-3])
class Solution: # def selection_sort(self, nums): # for i in range(len(nums)): # smallest = i # for j in range(i+1, len(nums)): # if nums[j] int: # nums = self.selection_sort(nums) nums.sort() result = 0 for i in range(0,len(nums), 2): result += nums[i] return result
class Solution: def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: # arr = [] -> 겹치는 숫자 저장하는 arr arr = [] for i in range(len(nums1)): for j in range(len(nums2)): if nums1[i] == nums2[j]: arr.append(nums1[i]) nums2.pop(j) break return arr # Time Complexity : O(n^..
class Solution: def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: arr = [] nums1 = set(nums1); nums2 = set(nums2) for num in nums1: if num in nums2: arr.append(num) return arr
Code 1) Not Used Setclass Solution: def containsDuplicate(self, nums: List[int]) -> bool: for i in range(len(nums)): for j in range(i+1, len(nums)): if nums[i] == nums[j]: return True return False # Time Complexity : O(n^2) # Space Complexity : O(1) Code 2) Used Setclass Solution: def containsDuplicate(self, nums: Lis..
[Level] Medium[Topics] Array Sorting Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.https://leetcode.com/problems/merge-intervals/ IdeaCodeclass Solution: def selection_sort(self, intervals): for i in range(len(intervals)): smalles..