Eat Study Love

먹고 공부하고 사랑하라

코린이 41

Sort Characters By Frequency(Hash Table,String,Sorting,Heap (Priority Queue),Bucket Sort,Counting)

https://leetcode.com/problems/sort-characters-by-frequency/description/Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.Return the sorted string. If there are multiple answers, return any of them. Example 1:Input: s = "tree"Output: "eert"Explanation: 'e' appears twice while 'r' and..

Coding_Practice 2024.11.18

Guess Number Higher or Lower II[Math,Dynamic Programming,Game Theory]

https://leetcode.com/problems/guess-number-higher-or-lower-ii/description/We are playing the Guessing Game. The game will work as follows:I pick a number between 1 and n.You guess a number.If you guess the right number, you win the game.If you guess the wrong number, then I will tell you whether the number I picked is higher or lower, and you will continue guessing.Every time you guess a wrong n..

Coding_Practice 2024.11.05

Binary Grid Question[Loop & Graph]

list of list[int] 의 data type을 받아서 가장 긴 connected 1's length를 반환하는 함수를 만들어야 한다. Matrix 는 2차원이다보니까 m*n Matrix를 생각하면 되고, 주어진 2차원 Matrix에서 어떤 것을 0에서 1로 바꿀 지 잘 고민해야하고 x, y축 index 헷갈리지 않게 주의해야 한다. 이거때문에 index overflow로 애좀 먹음.. 꿀팁은 python deque만 있으면 queue / stack 다 구현할 수 있다는 것이고, python의 경우 if 문에서 0  그리고 맨 처음 언급했듯이, x / y축 len과 idx following을 잘 해야 한다. 이런 종류의 문제는 무작정 coding에 들어가지 말고, 머릿속으로 또는 빈 종이에 구조를..

Coding_Practice 2024.11.04

Jump To Python 함수!Function! 4장 연습문제 [5]

함수영역까지 왔다. 클래스, 모듈 소환해서 사부작 사부작 할 수 있는 본게임에 앞서 마지막 몸풀기 단계라는 마음으로 연습문제를 풀어보자. # Q1. 주어진 자연수가 홀수인지 짝수인지 판별해 주는 함수(is_odd)를 작성해 보자. # def is_odd(x): # if x % 2 == 0: # print(f'{x}는 짝수입니다.') # else: # print(f'{x}는 홀수입니다.') # is_odd(2) # is_odd(5) 가볍다 ㅎㅎ # Q2. 입력으로 들어오는 모든 수의 평균값을 계산해 주는 함수를 작성해 보자. (단 입력으로 들어오는 수의 개수는 정해져 있지 않다.) # ※ 평균 값을 구할 때 len 함수를 사용 가볍지 않다.. 뭔가 문제 읽고 *args로 변수를 랜덤개수 만큼 받아야 겠다고..

Jump To Python if,for,while문 3장 연습문제 [4]

3장 가자가자! Q1. 아래를 실행했을 때 결과는? a = "Life is too short, you need python" # if "wife" in a: # print("wife") # elif "python" in a and "you" not in a : # print("python") # elif "shirt" not in a: # print("shirt") # elif "need" in a: # print("need") # else: # print("none") 정답 : shirt -> shirt need none이 아니다. if문 + elif문 에서는 한 번이라도 조건식이 True가 뜨면 거기서 STOP! 주의하세요~ Q2. # while문을 사용해서 1부터 1000까지의 자연수 중 3의 배수..

Jump To Python 2장 연습 문제(2) [2]

이어서 가보즈아 Q8. # (1,2,3) 튜플에 값 4를 추가하여 (1,2,3,4)를 만들어 출력하라 b를 저렇게 하니까 튜플이 아니라 int라 더하기가 안 된다고 한다. # a = (1,2,3) # b=(4,) # print(a+b) b 옆에 공백을 넣어서 a+b를 출력하니까 되네. 쉬운듯 까다로운 Tuple의 세계 Q9. # 다음과 같은 Dictionary a가 있다고 할 때, 오류가 발생하는 경우를 고르고 이유를 설명하라 # a=dict() # 1.a['name'] = 'python' # 2.a[('a',)]='python' # 3.a[[1]]='python' # 4.a[250]='python' A. 3번 => 키 값으로 list, set 등 변하는 값을 설정하지는 못한다 => 몰랐넹;; 그냥 나머..