boj-7785. 회사에있는사람 import sys input = sys.stdin.readline employee = set() for _ in range(int(input())): name, status = input().split() if status == "enter": employee.add(name) else: employee.remove(name) for name in sorted(employee, reverse=True): print(name) Algorithm/기본 알고리즘 2023.01.20
boj-1302. 베스트셀러 books = dict() for _ in range(int(input())): name = input() if name in books.keys(): books[name] += 1 else: books[name] = 1 max_profit_books = max(books.values()) arr = [] for k in books.keys(): if max_profit_books == books.get(k): arr.append(k) arr.sort() print(arr[0]) 카테고리 없음 2023.01.20
boj-2164. 카드 2 import collections N = 6 queue = collections.deque([i for i in range(1, N+1)]) print(list(queue)) print("-"*5) while queue : tmp = queue.popleft() last_num = queue.popleft() queue.append(last_num) # print(list(queue)) if len(queue) == 1: print(queue[0]) break Algorithm/기본 알고리즘 2023.01.19
boj-11866. 요세푸스 문제 import collections N, K = 7, 3 queue = collections.deque([i for i in range(1, N+1)] ) # print(list(queue)) joshep = [] while queue : for i in range(K-1): tmp = queue.popleft() queue.append(tmp) dead = queue.popleft() joshep.append(dead) print(joshep) Algorithm/기본 알고리즘 2023.01.19
leetcode 21. Merge Two Sorted Lists # Definition for singly-linked list. # class ListNode(object): # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution(object): def mergeTwoLists(self, list1, list2): """ :type list1: Optional[ListNode] :type list2: Optional[ListNode] :rtype: Optional[ListNode] """ if list1 is None: return list2 if list2 is None : return list1 head = None if list1.val < list2.v.. Algorithm/기본 알고리즘 2022.08.28
[기본 알고리즘] Binary Search print('Hello, world!') l = [1,2,3,4,5,6,7,8,9,10] target = 4 def binarySearch(l): left = 0 right = len(l) - 1 step = 0 while left target: right = pivot - 1 elif l[pivot] < target: left = pivot + 1 else : return pivot return -1 print(binarySearch(l)) 재귀 / 반복문으로 풀 수 있지만, 이왕이면 재귀를 지양하자는 의미에서 반복문으로만 풀어봄 Algorithm/기본 알고리즘 2022.08.28
지도에서 상하좌우 움직이기 def isOut(x, y): if N >= x > 0 and N >= y > 0 : # print(False) return False # print(True) return True def doAction(action) : global x, y, nx, ny nx = x ny = y if action == "R" : nx +=1 if action == "U" : ny -=1 if action == "D" : ny +=1 if isOut(nx, ny): # print("out", nx, ny) return x, y = nx, ny if __name__=="__main__": # plans = input().split() plans = ['R', 'R', 'R', 'U', 'D', 'D'] N = 5 x, .. Algorithm/기본 알고리즘 2022.08.27
Flask로 가볍게 네이버 로그인 API 구현해보기 요즘 구글, 페이스북, 네이버, 깃헙 등에서 제공하는 00으로 로그인하기 버튼을 본적이 꽤 있을 것이다. 이런 인증방식은 Oauth2.0이라고 부르며, 로그인의 표준으로 자리매김하고 있다. 다만 어디서 Client코드가, 어디서 Server 코드를 작성해야하는지 헷갈리는 경우가 있기 마련인데 Simple하게 구현해보기 위해서 Flask로 한번 구현해보자 (Flask를 해보진 않았어서, 한번 공부겸해서 구현해본다) 먼저 네이버로 로그인하기 API 명세이다. https://developers.naver.com/docs/login/devguide/devguide.md#3-4-%EB%84%A4%EC%9D%B4%EB%B2%84-%EB%A1%9C%EA%B7%B8%EC%9D%B8-%EC%97%B0%EB%8F%99-%.. Developement/Toy Project 2022.04.12
leetcode 206. Reverse Linked List 만약에 stack을 쓰게 된다면 O(2n)의 시간복잡도와 시간복잡도가 생기기 마련이다. 하지만 우리는 포인터 개념으로 여기에 접근하면 O(n)으로도 풀이가 가능하다 바로 이전에 저장했던 이전 node들을 저장해서 포인터의 방향을 반대로 바꾸는 것이다 코드를 한번 따라가보자 현재 노드를 뜻하는 curr가 2에 있다고 가정하자. 그렇다면 이전 노드를 뜻하는 prev는 1일 것이고, 3은 curr.next 가 될 것이다. 그렇다면 아래의 코드가 이해가 될 것이다 curr.next = prev 현재 curr 노드의 next는 prev 노드로 정한다 라는 뜻이다. 그럼 prev를 이제 현재 노드로 입력을 해두어야 다음 loop를 쓸 것이다 prev = curr 위와 같이 쓸 수 있다. 자 이제 2의 다음 node.. Algorithm/기본 알고리즘 2022.04.05
leetcode 46. Permutations 순열 https://leetcode.com/problems/permutations/ Permutations - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. Example 1: Input: nums = [1,2,3] Output: [[1,2,3],[1,3,.. Algorithm/기본 알고리즘 2022.04.03