코-딩

코-딩/프로그래머스

프로그래머스::개인정보 수집 유효기간

문제 : https://school.programmers.co.kr/learn/courses/30/lessons/150370 난이도 : Lv.1 풀이 def solution(today, terms, privacies): answer = [] termsDict = {t.split(" ")[0] : int(t.split(" ")[1])*28 for t in terms} td = today.split(".") tdDays = 12*28*int(td[0]) + 28*int(td[1]) + int(td[2]) for i,p in enumerate(privacies): diff = termsDict[p[-1]] p = p[:-2] pDays = 12*28*int(p.split(".")[0]) + 28 * int(p..

코-딩/프로그래머스

프로그래머스::숫자 문자열과 영단어

문제 : https://school.programmers.co.kr/learn/courses/30/lessons/81301 난이도 : Lv.1 풀이 def solution(s): if s.isdigit(): return int(s) numStr = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] for i in range(len(numStr)): s = s.replace(numStr[i], str(i)) return int(s)

코-딩/Leetcode

[leetcode] 392. Is Subsequence(python)

문제 : https://leetcode.com/problems/is-subsequence/description/ 난이도 : Easy 문자열 s가 t에 포함되어 있는지 찾는 문제다. 어떻게 할까 고민하다가 그냥 찾으면 그 위치부터 자르고, 찾으면 자르고 단순하게 풀기로 했다. (늘 그랬음;;) 풀이1 class Solution: def isSubsequence(self, s: str, t: str) -> bool: answer = False tIdx, sIdx = 0, 0 if len(s) > len(t): return False if len(s) == 0: return True while len(t) > 0 and tIdx > -1: tIdx = t.find(s[sIdx]) if(tIdx > -1): #..

코-딩/프로그래머스

프로그래머스::신규 아이디 추천

문제 : https://school.programmers.co.kr/learn/courses/30/lessons/72410 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 난이도 : Lv.1 입력으로 받은 문자열(new_id)을 아래와 같은 단계를 거쳐주기만 하면 된다. 1) new_id의 모든 대문자를 대응되는 소문자로 치환합니다. 2) new_id에서 알파벳 소문자, 숫자, 빼기(-), 밑줄(_), 마침표(.)를 제외한 모든 문자를 제거합니다. 3) new_id에서 마침표(.)가 2번 이상 연속된 부분을 하나의 마침표(.)로 치환합니다. 4) new_i..

코-딩/Leetcode

[leetcode] 669. Trim a Binary Search Tree (python)

문제 : https://leetcode.com/problems/trim-a-binary-search-tree/ 난이도 : Medium 풀이 class Solution: def trimBST(self, root: Optional[TreeNode], low: int, high: int) -> Optional[TreeNode]: def trim(node) -> Optional[TreeNode]: if node: if node.val > high: return trim(node.left) elif node.val < low: return trim(node.right) else: node.left = trim(node.left) node.right = trim(node.right) return node retur..

코-딩/Leetcode

[leetcode] 1422. Maximum Score After Splitting a String (python)

문제 : https://leetcode.com/problems/maximum-score-after-splitting-a-string/ 난이도 : Easy 풀이 1 class Solution: def maxScore(self, s: str) -> int: maxScore = 0 for i in range(1, len(s)): cnt = s[:i].count('0') + s[i:].count('1') maxScore = max(cnt, maxScore) return maxScore 단순하게 index를 기준으로 왼쪽은 0의 갯수를, 오른쪽은 1의 갯수를 세서 최댓값을 구하는 풀이이다. 풀이 2 class Solution: def maxScore(self, s: str) -> int: # 왼쪽 0의 갯수 + ..

힞뚜루마뚜루
'코-딩' 카테고리의 글 목록 (5 Page)