파이썬(24)
-
[Python 문제풀이] 11일차
Day_11 Intro Q17. arrayChange You are given an array of integers. On each move you are allowed to increase exactly one of its element by one. Find the minimal number of moves required to obtain a strictly increasing sequence from the input. 제출 코드 def arrayChange(inputArray): AddNum = 0 for i in range(len(inputArray) -1): if inputArray[i] >= inputArray[i+1]: AddNum += inputArray[i] + 1 - inputArr..
2020.07.19 -
[Python 문제풀이] 10일차
Day_10 Intro Q16. Are Similar? Two arrays are called similar if one can be obtained from another by swapping at most one pair of elements in one of the arrays. Given two arrays a and b, check whether they are similar. 제출 코드 def areSimilar(a, b): if a == b: # 둘이 같으면 참 return True else: # 다를 때 # 정렬한 값이 같은 경우, 스왑해야하는 갯수를 체크하면 된다 c = sorted(a) d = sorted(b) diffCount = 0 # 정렬한 값이 같은 경우 if c == d: fo..
2020.07.18 -
[Python 문제풀이] 9일차
Day_9 Intro Q14. alternatingSums Several people are standing in a row and need to be divided into two teams. The first person goes into team 1, the second goes into team 2, the third goes into team 1 again, the fourth into team 2, and so on. You are given an array of positive integers - the weights of the people. Return an array of two integers, where the first element is the total weight of tea..
2020.07.17 -
[Python 문제풀이] 8일차
Day_8 Intro Q13. reverseInParentheses Write a function that reverses characters in (possibly nested) parentheses in the input string. Input strings will always be well-formed with matching ()s. def reverseInParentheses(inputString): #[출처] [python] codeSignal 문제풀이 (13~15)|작성자 Jun s = inputString while '(' in s : #괄호가 다 없어질때까지 반복 fb = s.rfind('(') # rfind : 뒤에서부터 문자열 탐색 bb = s[fb:]..
2020.07.16 -
[Python 문제풀이] 7일차
Day_7 Intro. Q12. Sort by Height Some people are standing in a row in a park. There are trees between them which cannot be moved. Your task is to rearrange the people by their heights in a non-descending order without moving the trees. People can be very tall! def sortByHeight(a): IdxSet_minus1 = [] sort_a = [] cnt_minus1 = 0 cnt_sort = 0 for i in range(len(a)): if a[i] == -1: IdxSet_minus1.appe..
2020.07.15 -
[Python 문제풀이] 6일차
Day_6 Intro. Q11. isLucky Ticket numbers usually consist of an even number of digits. A ticket number is considered lucky if the sum of the first half of the digits is equal to the sum of the second half. Given a ticket number n, determine if it's lucky or not. def isLucky(n): n_str = str(n) n_list = list(n_str) sumFront = 0 sumSecond = 0 for i in range(len(n_list)): if i < len(n_list)/2: su..
2020.07.14