일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- dfs
- 혁펜하임
- 백준 2309
- softeer
- til
- 딥러닝
- 프로그래머스
- 개발자 취업
- BOJ
- 해시
- 스택
- 백준
- 99항해
- 큐
- 파이썬
- 알고리즘
- boj 2309
- 코딩테스트준비
- 활성화 함수
- 기능개발
- 코딩테스트 준비
- 구현
- python 2309
- easy 딥러닝
- 개발자취업
- 항해99
- leetcode
- 99클럽
- Python
- BFS
- Today
- Total
목록문제 풀이 (92)
동까의 코딩
https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/submissions/1299761990/ 오늘의 문제는 괄호 스택 문제입니다. 예전에 스택 관련해서 문제를 많이 풀어봐서 빠르게 풀게되었습니다. 먼저 (가 입력되면 stack에 채워줍니다. 그리고 )닫히는 괄호가 나오면 pop을 해줘서 stack에서 최근 것을 빼줍니다.하지만 stack이 비어있을 때 )가 입력되는 경우도 있으니 이 때는 카운트를 해줍니다.그리고 마지막으로 stack에 ( 입력이 쌓여있을 수 있으니 카운트 값에 마지막에 stack의 들어있는 개수만큼 더해주어 구현하였습니다. class Solution: def minAddToMakeValid(self, s: st..
https://leetcode.com/problems/removing-stars-from-a-string/submissions/1298504525/ class Solution: def removeStars(self, s: str) -> str: st = [] for i in s: if i == '*' and len(st) != 0: st.pop() else: st.append(i) answer = "" if len(st) != 0: for i in st: answer += i return answer..
https://leetcode.com/problems/flatten-nested-list-iterator/ class NestedIterator(object): def __init__(self, nestedList): def dfs(nestedList): for item in nestedList: if item.isInteger(): self.stack.append(item.getInteger()) else: dfs(item.getList()) self.stack = [] dfs(nestedList) d..
https://leetcode.com/problems/find-the-winner-of-the-circular-game/ class Node: def __init__(self, v): self.val = v self.next = None self.prev = Noneclass Solution: def findTheWinner(self, n: int, k: int) -> int: start_node = cur_node = Node(1) prev_node = None for i in range(2, n + 1): new_node = Node(i) cur_node.next = new_n..
https://leetcode.com/problems/reordered-power-of-2/description/ import itertoolsclass Solution: def reorderedPowerOf2(self, n: int) -> bool: cnt = 0 answer = False n = str(n) num_list = [] for i in n: num_list.append(i) nCr = itertools.permutations(num_list, len(num_list)) num_list = [] nCr = list(nCr) for i in range(le..
https://leetcode.com/problems/top-k-frequent-elements/submissions/1294689495/ 정렬하여 카운트를 해주고, 많은 숫자를 보여한 숫자를 정답칸에 K만큼 저장해주고 반환하는 문제입니다. class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: cnt = {} cnt_list = [[] for _ in range(len(nums) + 1)] answer = [] for num in nums: cnt[num] = 1 + cnt.get(num, 0) for key, val in cnt.i..
https://leetcode.com/problems/sort-characters-by-frequency/description/ class Solution: def frequencySort(self, s: str) -> str: m = {} for c in s: if c not in m: m[c] = 1 else: m[c] += 1 li = sorted([(m[i], i) for i in m], reverse=True) res = [] for count, c in li: res.append(c * count) ..
https://leetcode.com/problems/minimum-suffix-flips/submissions/1291875785/ 오늘의 문제는 leetcode의 문자열 문제입니다. class Solution: def minFlips(self, target: str) -> int: acc=0 for i in range(len(target)): if target[i]=="0" and acc%2==0 or target[i]=="1" and acc%2==1: continue else: acc+=1 return acc