본문 바로가기

Python345

자료구조 _ Array와 Dynamic Array Array는 무엇인가요? Array는 데이터를 메모리상에 연속적으로, 미리 할당된 크기만큼 저장하는 자료구조 입니다. Array의 특징 - 고정적 저장 공간이 필요합니다. - 메모리에 연속적으로 저장합니다. 시간복잡도 - 램덤액세스(즉시 접근 가능 - 순차(X)) 방식이기 때문에 조회는 O(1)입니다. - 마지막 삽입, 삭제도 O(1)입니다. - 다만 일반 삽입, 삭제는 O(n)입니다. 장단점 - Array의 장점은 조회가 빠르다는 것입니다. - Array의 단점은 고정된 저장 공간을 필요로 하기 때문에 Array의 크기를 미리 정해야 한다는 것입니다. - 때문에 메모리 낭비나 추가적인 오버헤드가 발생할 수 있습니다. *오버헤드 : Array 크기를 변경하면서 데이터 이동에 따라 발생하는 리소스 데이터가.. 2022. 3. 17.
Meeting Description: John has invited some friends. His list is: s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill"; Could you make a program that makes this string uppercase gives it sorted in alphabetical order by last name. When the last names are the same, sort them by first name. Last name and first name of a guest come in the result betwe.. 2022. 3. 17.
English beggars Description: Born a misinterpretation of this kata, your task here is pretty simple: given an array of values and an amount of beggars, you are supposed to return an array with the sum of what each beggar brings home, assuming they all take regular turns, from the first to the last. For example: [1,2,3,4,5] for 2 beggars will return a result of [9,6], as the first one takes [1,3,5], the second c.. 2022. 3. 16.
Kebabize Description: Modify the kebabize function so that it converts a camel case string into a kebab case. kebabize('camelsHaveThreeHumps') // camels-have-three-humps kebabize('camelsHave3Humps') // camels-have-humps Notes: the returned string should only contain lowercase letters Solution: 1. Repeat the string with a for statement. 2. If there is a number, pass. 3. If there is a capital letter, add '.. 2022. 3. 16.
+1 Array Description: Given an array of integers of any length, return an array that has 1 added to the value represented by the array. the array can't be empty only non-negative, single digit integers are allowed Return nil (or your language's equivalent) for invalid inputs. Examples For example the array [2, 3, 9] equals 239, adding one would return the array [2, 4, 0]. [4, 3, 2, 5] would return [4, 3,.. 2022. 3. 15.
Python _ 리스트 요소 개수 세기(dictionary, collections) 리스트에 어떤 요소의 개수를 파악해야하는 때가 있습니다. (특히 코딩테스트에서 사용할 일이 많습니다) 그래서 오늘은 요소 개수를 세는 방법을 정리해보고자 합니다. dictionary 사용 # 요소를 세고 싶은 리스트 >>> list = [1,2,3,4,5,5,5,5,5,1,1] # 빈 딕셔너리를 생성 >>> dict = {} # 요소가 딕셔너리에 있다면 += 1, 없다면 = 1 >>> for num in list: if num in dict: # dict.get(num)로 대체가능 dict[num] += 1 else: dict[num] = 1 # {요소(키): 개수(값)} 형태의 딕셔너리 생성 >>> dict {1: 3, 2: 1, 3: 1, 4: 1, 5: 5} 기본 딕셔너리를 사용하는 베이직한 방법입.. 2022. 3. 6.