Cute Running Puppy
반응형

algorithm 35

[python]5. Longest Palindromic Substring

Longest Palindromic Substring - LeetCode Longest Palindromic Substring - 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. 가장 긴 팰린드롬인지 확인 틀린 풀이 class Solution: def longestPalindrome(self, s: str) -> str: # 팰린드롬을 담을 리스트 p..

[python] 937. Reorder Data in Log Files

https://leetcode.com/problems/reorder-data-in-log-files/ 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. 식별자는 순서에 영향을 미치지 않는다, 문자가 동일할경우 식별자 순으로 정렬한다 4. 숫자 로그는 입력 순서대로 정렬한다 cla..

[python] 344. Reverse String

https://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을 사용하면 안된다) 풀이 1. class Solution: def reverseString(self, s: List[str]) -> None: s.reverse() reverse 함수를 사용 (reverse 함수는 리스트에만 적용가능) (결과) Runtime: 379 m..

[python] 125. Valid Palindrome

https://leetcode.com/problems/valid-palindrome/ Valid Palindrome - 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. class Solution: def isPalindrome(self, s: str) -> bool: s = ''.join(char for char in s if char.isalpha(..

[python] 5622_다이얼

https://www.acmicpc.net/problem/5622 5622번: 다이얼 첫째 줄에 알파벳 대문자로 이루어진 단어가 주어진다. 단어의 길이는 2보다 크거나 같고, 15보다 작거나 같다. www.acmicpc.net string = list(input()) dial = { 3: ["A", "B", "C"], 4: ["D", "E", "F"], 5: ["G", "H", "I"], 6: ["J", "K", "L"], 7: ["M", "N", "O"], 8: ["P", "Q", "R", "S"], 9: ["T", "U", "V"], 10: ["W", "X", "Y", "Z"] } res = 0 for i in string: for j in range(3, 11): if i in dial[j]: re..

[python] 2941_크로아티아 알파벳

https://www.acmicpc.net/problem/2941 2941번: 크로아티아 알파벳 예전에는 운영체제에서 크로아티아 알파벳을 입력할 수가 없었다. 따라서, 다음과 같이 크로아티아 알파벳을 변경해서 입력했다. 크로아티아 알파벳 변경 č c= ć c- dž dz= đ d- lj lj nj nj š s= ž z= www.acmicpc.net cro = ["c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="] alpha = input() for i in cro: if i in alpha: ''' alpha = alpha.replace(i, '') res += 1 발견한 크로아티아 문자를 없애면 중복된 크로아티아 문자를 셀 수 없다. ''' alpha = alpha.r..

[python] 1712_손익분기점

https://www.acmicpc.net/problem/1712 1712번: 손익분기점 월드전자는 노트북을 제조하고 판매하는 회사이다. 노트북 판매 대수에 상관없이 매년 임대료, 재산세, 보험료, 급여 등 A만원의 고정 비용이 들며, 한 대의 노트북을 생산하는 데에는 재료비와 www.acmicpc.net a, b, c = map(int, input().split()) if (b >= c): res = -1 else: res = int(a / (c - b)) + 1 print(type(round(a / (c - b)))) print(res) 1. b == c 일 때에도 손익분기점이 계산되지 않는다. 2. 계산 결과를 int 형으로 변환하는 것을 잊지 않아야 한다.

[python] 2292_벌집

https://www.acmicpc.net/problem/2292 2292번: 벌집 위의 그림과 같이 육각형으로 이루어진 벌집이 있다. 그림에서 보는 바와 같이 중앙의 방 1부터 시작해서 이웃하는 방에 돌아가면서 1씩 증가하는 번호를 주소로 매길 수 있다. 숫자 N이 주어졌 www.acmicpc.net num = int(input()) honeycomb = [1] while(1): if (num == 1): break else: honeycomb.append(honeycomb[-1] + (6 * len(honeycomb))) if(honeycomb[-1] >= num): break print(len(honeycomb)) 계차수열의 값들을 계산해서 리스트에 넣고 리스트의 개수를 세는 방식으로 코드를 작성하..

[python]level1. 키패드 누르기

https://programmers.co.kr/learn/courses/30/lessons/67256 코딩테스트 연습 - 키패드 누르기 [1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5] "right" "LRLLLRLLRRL" [7, 0, 8, 2, 8, 3, 1, 5, 7, 6, 2] "left" "LRLLRRLLLRR" [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] "right" "LLRLLRLLRL" programmers.co.kr 정답 코드 def solution(numbers, hand): answer = '' key = [[1, 2, 3], [4, 5, 6], [7, 8, 9], ['*', 0, '#']] left = [1, 4, 7, '*'] right = [3, 6, 9,..

[python] 백준 2908_상수

https://www.acmicpc.net/problem/2908 2908번: 상수 상근이의 동생 상수는 수학을 정말 못한다. 상수는 숫자를 읽는데 문제가 있다. 이렇게 수학을 못하는 상수를 위해서 상근이는 수의 크기를 비교하는 문제를 내주었다. 상근이는 세 자리 수 두 www.acmicpc.net a, b = list(input().split()) new_a = [] new_b = [] for i in a: new_a.insert(0, i) for i in b: new_b.insert(0, i) new_a = ''.join(new_a) new_b = ''.join(new_b) print(max(new_a, new_b))