파이썬 기초 문제(4)
-
[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 문제풀이] 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 -
[Python 문제풀이] 5일차
Day_5 Q10. commonCharacterCount Given two strings, find the number of common characters between them. def commonCharacterCount(s1, s2): s3 = list(s1) s4 = list(s2) save = list() if len(s3) >= len(s4): for i in range(len(s4)): Character = s4[i] try: Idx = s3.index(Character) except: pass else: save.append(s3.pop(Idx)) else: for i in range(len(s3)): Character = s3[i] try: Idx = s4.index(Character)..
2020.07.13