🌿All posts 199

✏️ [LeetCode] 5. Longest Palindromic Substring

1. 문제 https://leetcode.com/problems/longest-palindromic-substring/ Longest Palindromic Substring - 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 2. 접근 방법 일단 문제는 주어진 문자열 내에 존재하는 가장 긴 팰린드롬 부분 문자열을 찾으면 됩니다. 팰린드롬은 앞뒤가 같은 문자인데요, 예를 들면 "aba"와 같이 앞에서 봐도, 뒤에서 봐도 같은 문자열을 말합니다 팰린드롬의 종류에는 "..

Algorithm/Python 2021.06.03

✏️ [LeetCode] 49. Group Anagrams

1. 문제 https://leetcode.com/problems/group-anagrams/ Group Anagrams - 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 2. 접근 방법 딕셔너리를 사용해서 애너그램 단위로 묶어줍니당 3. 코드 Python3 class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: anagrams = dict() for s in strs: sort_s..

Algorithm/Python 2021.06.03

✏️ [LeetCode] 937. Reorder Log Files

1. 문제 https://leetcode.com/problems/reorder-data-in-log-files Reorder Data in Log Files - 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 2. 접근 방법 일단 문제는 주어진 logs라는 리스트를 잘 확인하는 것 리스트의 각 요소는 str형식인데 그 안에서 띄어쓰기를 기준으로 맨 앞의 단어는 identifier이고, identifier 뒤에 나온 것들이 숫자인 경우에는 : Digit-logs i..

Algorithm/Python 2021.06.02

✏️ [LeetCode] 344. Reverse String

1. 문제 https://leetcode.com/problems/reverse-string Reverse String - 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 2. 접근 방법 문자열 뒤짚기인데, 슬라이싱 사용해서 s[::-1]이렇게 풀ㄹ면 안된다.. 왜냐면 공간 복잡도를 O(1)로 제한 했기 때무니다 ... 그래서 reverse()를 사용해따 3. 코드 python class Solution: def reverseString(self, s: List[s..

Algorithm/Python 2021.06.01

✏️ [LeetCode] 125. Valid Palindrome

1. 문제 https://leetcode.com/problems/valid-palindrome/ Valid Palindrome - 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 2. 접근 방법 주어진 문자열이 팰린드롬인지 확인하면 됩니다. 문자열을 확인하는 방법은 여러 가지가 있는ㄷㅔ용 1. 리스트 2. 데크 저는 deque를 사용했슴다 왜냐면 리스트는 pop(0)이 O(n)이지만 데크는 popleft()가 O(1)이니까여 3. 코드 python3 class S..

Algorithm/Python 2021.06.01

✏️ [백준 1759] 암호만들기

1. 문제 https://www.acmicpc.net/problem/1759 2. 접근 방법 주어진 C개의 문자 중 L개의 문자를 골랐을 때, 확인해야할 것은 1. 최소 한 개의 모음을 가지고 있는가 2. 최소 두 개의 자음을 가지고 있는가 3. 증가하는 순서인가 이다. 일단 3을 만족시키기 위해, input받은 문자들을 정렬시켰다. 정렬 시킨 후 L개의 문자를 고르도록 한다. (이렇게 되면 사전 순서가 지켜지니까) 그리고 나서 C개의 문자를 골랐다면 1, 2번을 만족하는지 확인한다. 3. 코드 python def isPassword(word): vowels = ['a', 'e', 'i', 'o', 'u'] v_cnt = 0 for i in word: if i in vowels: v_cnt += 1 c_..

Algorithm/Python 2021.05.27

✏️ [백준 11723] 집합

1. 문제 https://www.acmicpc.net/problem/11723 11723번: 집합 첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다. www.acmicpc.net 2. 접근 방법 그리디하게 접근했는데 시간초과 메모리초과 모두 나서 ㄷㅏ시 짰습니다요 .. 일단 시간 초과 때문에 input()대신 sys.stdin으로 입력받아야합니다. 그리고 메모리 초과 때문에 정답을 리스트에 담지 않고 check가 나왔을 때는 바로바로 프린트를 해줘야합니다. 처음에는 set으로 접근했지만 연산에도 시간이 많이 소요될 것 같아 숫자가 1~21이기 때문에 불리언 값으로 접근했습니다. (원래 add(),..

Algorithm/Python 2021.05.26

✏️ [백준 10819] 차이를 최대로

1. 문제 https://www.acmicpc.net/problem/10819 10819번: 차이를 최대로 첫째 줄에 N (3 ≤ N ≤ 8)이 주어진다. 둘째 줄에는 배열 A에 들어있는 정수가 주어진다. 배열에 들어있는 정수는 -100보다 크거나 같고, 100보다 작거나 같다. www.acmicpc.net 2. 접근 방법 주어지는 숫자의 갯수가 2~8이라 순열을 사용해도 되겠다 싶었습니다. 1. 순열을 만들기 전에 미리 요소 하나를 담고 2. 여기에 요소 하나를 추가할 때마다 기존 순열 리스트에 담겨있는 맨 마지막 숫자와의 차이를 변수에 담아줍니다. 3. 순열 리스트의 요소 갯수가 N개가 되었을 때, 숫자들의 차이를 합친 변수의 크기가 기존 최댓값보다 클 경우 갱신해줍니다. 3. 코드 python de..

Algorithm/Python 2021.05.25

✏️ 6. 프로세스 동기화 & 상호배제 (7) - Monitor

강의 링크 : https://www.youtube.com/watch?v=AnYN-kbCbRI&list=PLBrGAFAIyf5rby7QylRc6JxU5lzQ9c4tN&index=18 0. 들어가기에 앞서 이번 포스팅에서 다룰 내용은 Monitor입니다. 이는, 앞에서 다룬 Low-level mechanisms(SW solution, HW solution, OS supported SW solution)과는 달리, Language-Level solution으로써 프로그래밍 언어적으로 상호배제를 해결하는 방법입니다. 그 동안 한 Low-level mechanisms들은 다음과 같은 특징이 있었습니다. Flexible : 다양하게 적용 가능하다 Difficult to use : 구현이 복잡하다 Error-pron..

CS/OS 2021.05.14