Algorithm/1일 1코테
-
[🥲 프로그래머스] 등굣길 - Dynamic programmingAlgorithm/1일 1코테 2021. 7. 21. 21:33
https://programmers.co.kr/learn/courses/30/lessons/42898 코딩테스트 연습 - 등굣길 계속되는 폭우로 일부 지역이 물에 잠겼습니다. 물에 잠기지 않은 지역을 통해 학교를 가려고 합니다. 집에서 학교까지 가는 길은 m x n 크기의 격자모양으로 나타낼 수 있습니다. 아래 그림은 m = programmers.co.kr ✅ 내 풀이 (망!) # 시간초과ㅜㅜ def solution(m, n, puddles): to_house = [] answer = [] # 격자만큼의 배열 생성 for i in range(n): to_house.append([True]*m) # 웅덩이 위치는 false로 변경 for puddle in puddles: x = puddle[0]-1 y =..
-
[🥲 프로그래머스] 정수 삼각형 - Dynamic ProgrammingAlgorithm/1일 1코테 2021. 7. 20. 21:21
https://programmers.co.kr/learn/courses/30/lessons/43105 코딩테스트 연습 - 정수 삼각형 [[7], [3, 8], [8, 1, 0], [2, 7, 4, 4], [4, 5, 2, 6, 5]] 30 programmers.co.kr ✅ 내가 쓴 답 # 내 광탈한 풀이!!!!! def solution(triangle): answer = [] for i in range(len(triangle)): if i == 0: answer.append(triangle[i]) continue temp = [] for j in range(i-1, i): for idx, n in enumerate(triangle[i]): for idx2, m in enumerate(answer[j])..
-
[🥲 프로그래머스] N으로 표현 (Dynamic Programming)Algorithm/1일 1코테 2021. 7. 19. 21:47
https://programmers.co.kr/learn/courses/30/lessons/42895 코딩테스트 연습 - N으로 표현 programmers.co.kr 🥺 내가 푼 풀이 # 내가 푼 풀이 44.4점 ㅜㅜ # 리스트가 들어오면, 해당 리스트에 사칙연산을 해주는 함수 def DP(N, l): answer = [] for i in l: answer.append(i+N) answer.append(i*N) answer.append(i-N) answer.append(i/N) return answer + l def solution(N, number): l = [] answer = 0 for idx in range(1, 9): # 최대 8번까지 시행 l.append(int(str(N)*idx)) # 5,..
-
[프로그래머스] 2단계 신규 아이디 추천Algorithm/1일 1코테 2021. 6. 23. 20:44
프로그래머스 2단계. 신규 아이디 추천 https://programmers.co.kr/learn/courses/30/lessons/72410# # 테스트코드 4개 통과 못 함.... def solution(new_id): # 허용되는 특수문자 리스트 ok_list = ['-', '_', '.'] # 소문자로 바꾸고, ok_list 안에 있거나 알파벳, 숫자 n_id=[i for i in new_id.lower() if i in ok_list or i.isalnum()] # 답안 변수 생성 answer = '' # ..이 여러개 붙어 있을 경우에 패스 for i in range(len(n_id)-1): if n_id[i] == '.' and n_id[i+1] == '.': continue else: ans..
-
[프로그래머스] H-indexAlgorithm/1일 1코테 2021. 6. 11. 22:19
https://programmers.co.kr/learn/courses/30/lessons/42747 코딩테스트 연습 - H-Index H-Index는 과학자의 생산성과 영향력을 나타내는 지표입니다. 어느 과학자의 H-Index를 나타내는 값인 h를 구하려고 합니다. 위키백과1에 따르면, H-Index는 다음과 같이 구합니다. 어떤 과학자가 발표 programmers.co.kr 코딩테스트 연습 - H-Index H-Index는 과학자의 생산성과 영향력을 나타내는 지표입니다. 어느 과학자의 H-Index를 나타내는 값인 h를 구하려고 합니다. 위키백과1에 따르면, H-Index는 다음과 같이 구합니다. 어떤 과학자가 발표 programmers.co.kr 1차풀이 # 카운트 딕셔너리 생성 d = collec..
-
[leetcode] 1. Two SumAlgorithm/1일 1코테 2021. 5. 4. 19:08
leetcode.com/problems/two-sum/submissions/ Two Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 내 풀이 for i in range(len(nums)): t = target - nums[i] if t in nums and nums.index(t) != i: return nums.index(t), i 해쉬를 이용한 풀이 class Solution: def twoSum(self, nums: List[int], target..
-
[leetcode] 819. Most Common WordAlgorithm/1일 1코테 2021. 4. 28. 14:21
819. Most Common Word leetcode.com/problems/most-common-word/ Most Common Word - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 조건 1. 금지어는 제거할 것 2. 특수문자 제거할 것 3. 소문자 혹은 대문자로 통일할 것 나의 답 def mostCommonWord(self, paragraph: str, banned: List[str]) -> str: import re # 전처리 paragraph = ..
-
[leetcode] 937. Reorder Log FilesAlgorithm/1일 1코테 2021. 4. 28. 09:12
leetcode.com/problems/reorder-data-in-log-files/submissions/ Reorder Data in Log Files - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 로그를 재정렬 하는 문제 조건은 1. 문자가 숫자의 앞 2. 제일 앞 문자가 동일할 경우 식별자 순으로 나열 3. 숫자로그는 입력 순서대로 처음에 생각한 건 sort로 정렬시킨 다음에 문자/숫자 나누려고 했는데 그러면 숫자로그가 입력순이 아니게 됨 결국 하나하..