Algorithm
-
[프로그래머스] 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로 정렬시킨 다음에 문자/숫자 나누려고 했는데 그러면 숫자로그가 입력순이 아니게 됨 결국 하나하..
-
[leetcode] 344. Reverse StringAlgorithm/1일 1코테 2021. 4. 14. 19:56
문제 leetcode.com/problems/reverse-string/ Reverse String - 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 return할 필요없이 s 안의 값만 변경하는 문제. 단, 새로운 list 생성 등을 하면 안되고 s 안에서만 변경해야 한다. 모범답안 class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s ..
-
[leetcode] 125.Valid PalindromeAlgorithm/1일 1코테 2021. 4. 14. 19:35
문제 입력 문자열이 팰린드롬인지 확인하는 문제 leetcode.com/problems/valid-palindrome/ # 내 답 class Solution: def isPalindrome(self, s: str) -> bool: p = '' # 전처리한 str 담아줄 변수 for i in s: if i.isalpha() or i.isdigit(): # 알파벳이거나 숫자일때만 i = i.lower() # 소문자로 바꿔준 뒤 더해줌 p += i p2 = p[::-1] # 팰린드롬인지 비교하기 위해 뒤집음 for i in range(len(p)): if p[i] != p2[i]: # 0번째부터 하나씩 출력해서 다르면 False return False return True isalpha() + isdigit()..
-
[🐉 백준 13단계] 백트래킹Algorithm/1일 1코테 2021. 1. 4. 15:45
백트래킹: 조건에 따른 모든 조합의 수를 찾는 것. 15649 import itertools a, b = input().split() l = [i for i in range(1, int(a)+1)] s = list(itertools.permutations(l, int(b))) for s in s: a = '' for i in s: a += str(i) a += ' ' print(a) 15650 import itertools a, b = input().split() l = [i for i in range(1, int(a)+1)] s = list(itertools.combinations(l, int(b))) for s in s: a = '' for i in s: a += str(i) a += ' ' prin..
-
[🦩 프로그래머스] 하샤드수, 124 숫자의 나라Algorithm/1일 1코테 2020. 12. 28. 11:26
하샤드 수 def solution(x): a = list(map(int, str(x))) # x를 자릿수별로 짤라서 list if x%sum(a) == 0: # x를 a의 합으로 나눈 나머지가 0이면 True return True return False 124 숫자의 나라 def solution(n): answer = '' while n > 0: n -= 1 answer = '124'[n%3] + answer n //= 3 return answer