본문 바로가기

전체 글192

프로그래머스 / 괄호 변환 / 파이썬 https://programmers.co.kr/learn/courses/30/lessons/60058 코딩테스트 연습 - 괄호 변환 카카오에 신입 개발자로 입사한 "콘"은 선배 개발자로부터 개발역량 강화를 위해 다른 개발자가 작성한 소스 코드를 분석하여 문제점을 발견하고 수정하라는 업무 과제를 받았습니다. 소스를 programmers.co.kr def divider(p): left = 0 right = 0 for i in range(len(p)): if p[i] == "(": left += 1 else: right += 1 if left == right: if i+1 < len(p): return p[:i+1], p[i+1:] else: return p, "" def changer(u,v): change.. 2022. 2. 13.
프로그래머스 / 124의 나라 / 파이썬 https://programmers.co.kr/learn/courses/30/lessons/12899 코딩테스트 연습 - 124 나라의 숫자 programmers.co.kr def solution(n): answer = '' while n: if n%3 ==0: answer = str(4) + answer n = n//3 - 1 else: answer = str(n%3) + answer n = n//3 return answer 3진법을 생각하면 쉽다. 단 기존과 다르게 끝이 4이므로 이 부분만 신경 써주면 된다. 2022. 2. 13.
HackerRank / Circular Array Rotation / Python https://www.hackerrank.com/challenges/circular-array-rotation/problem?isFullScreen=true Circular Array Rotation | HackerRank Print the elements in an array after 'k' right circular rotation operations. www.hackerrank.com #!/bin/python3 import math import os import random import re import sys # # Complete the 'circularArrayRotation' function below. # # The function is expected to return an INTEGE.. 2022. 1. 7.
HackerRank / Picking Numbers / Python https://www.hackerrank.com/challenges/picking-numbers/problem?isFullScreen=true Picking Numbers | HackerRank What's the largest size subset can you choose from an array such that the difference between any two integers is not bigger than 1? www.hackerrank.com 문제 해석을 잘 해야된다. 주어진 리스트 안에서 한개의 인자를 고를 수 있다. 해당 인자와 해당 인자들 다른 인자들과 비교했을때 같거나 1만큼 작은 인자들로 리스트를 만들때 가장 긴 리스트의 길이를 돌려준다. def pickingNumbers(a).. 2022. 1. 7.
HackerRank / Drawing Books / Python https://www.hackerrank.com/challenges/drawing-book/problem?isFullScreen=true Drawing Book | HackerRank How many pages does a student need to turn to get to page p? www.hackerrank.com 가장 빠르게 원하는 페이지에 다가가는 문제인데 첫 장이 0 1 이므로 n과 p를 2로 나눴을때 몫만 확인하면 된다. def pageCount(n, p): full_page = n // 2 want_page = p // 2 return min(want_page, full_page-want_page) #앞에서 뒤에서 2022. 1. 5.
HackerRank / Append and Delete / Python https://www.hackerrank.com/challenges/append-and-delete/problem?isFullScreen=true Append and Delete | HackerRank Can you convert $s$ to $t$ by performing exactly $k$ operations? www.hackerrank.com s문자를 t문자로 치환해야한다. 무조건 k번을 제거/추가해야한다. 1. 문자는 뒤에서부터 제거할 수 있다. 2. 문자를 추가할 때는 무조건 뒤에 추가된다. 3. 만약 k번보다 횟수가 남을때는 빈 s문자열에 제거가 가능하며 1회 차감된다. 문제 풀이 방법 s와 t의 길이의 합보다 k가 크면 상관없다. 계속 3번 조건을 시행하면 된다. 문제는 s와 t의 길이의 .. 2022. 1. 5.
HackerRank / Strange Counter / Python https://www.hackerrank.com/challenges/strange-code/problem?isFullScreen=true def strangeCounter(t): # Write your code here n_start = 3 n = 3 n_last = 0 #전에 n값을 저장 while t > n: n_last = n a = n*2 n = a + n_start length = n - n_last return length - (t-n_last) +1 2022. 1. 3.
HackerRank / Games of Thrones - 1 / Python https://www.hackerrank.com/challenges/game-of-thrones/problem?isFullScreen=true s를 재정렬해서 좌우대칭이 되면 된다. 홀수번 등장하는 인자가 2번 이상 나오면 불가능하다. def gameOfThrones(s): # Write your code here limit = 0 for ss in set(s): if s.count(ss) % 2 == 1: limit += 1 if limit >= 2: return "NO" else: return "YES" 2022. 1. 2.
HackerRank / Two Strings / Python https://www.hackerrank.com/challenges/two-strings/problem?isFullScreen=true Two Strings | HackerRank Given two strings, you find a common substring of non-zero length. www.hackerrank.com s1과 s2가 겹치는 단어가 있으면 Yes 없으면 No def twoStrings(s1, s2): # Write your code here for s in s1: if s in s2: return "YES" return "NO" 2022. 1. 2.