본문 바로가기

전체 글

(154)
[python] Leetcode 98. Validate Binary Search Tree https://leetcode.com/problems/validate-binary-search-tree/description/ Validate Binary Search Tree - 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 문제 소개 요약 : 해당 함수가 BST(이진 탐색 트리)가 맞는 지 확인하는 문제다 관련 토픽 : DFS, BST BST 이진 탐색 트리는 현재 노드와 비교하여 왼쪽에는 작은 값의 노드가, 오른쪽에는 큰 값의 노드가 존재하는 트리를 의미한..
[python] Leetcode 79. Word Search https://leetcode.com/problems/word-search/ Word Search - 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 문제 소개 요약: 그래프 내 알파벳이 연속으로 이어져서 찾는 단어가 될 수 있다면 True를 반환하는 문제 관련 토픽 : DFS Code & 설명 def exist(self, board, word): global answer def dfs(x, y, dfs_word,visited, word) : global answ..
[python] Leetcode 54. Spiral Matrix https://leetcode.com/problems/spiral-matrix/ Spiral Matrix - 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 문제 소개 흔히 말하는 달팽이 문제이다! 요약: 막히면 90도 회전한다. 이 방문순서를 담은 배열을 구하시오 관련 토픽 : dfs, graph Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,3,6,9,8,7,4,5] 매우 다양한 풀이가 존재하는데 graph ..
[python] Leetcode 34. Find First and Last Position of Element in Sorted Array https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ Find First and Last Position of Element in Sorted Array - 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 문제 소개 target과 동일한 숫자가 nums 배열안에 있다면, 그 숫자의 시작과 끝 index를 반환, 없다면 [-1,-1]를 반환하는 문제 O(log n)..
[python] Leetcode 15. 3Sum https://leetcode.com/problems/3sum/description/ 3Sum - 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 문제 소개 주어진 배열에서 숫자 3개의 합이 0인 배열들의 리스트를 리턴하는 문제이다. 순열을 통해 완전 탐색을 할 경우 시간초과가 나온다. 투 포인터와 그리디 알고리즘을 사용한 두 가지 추천 코드를 참고하여 풀었고 해당 풀이를 소개한다. Two Pointer Code def threeSum(self, nums): nu..
Modal 중앙 정렬 하는 법 모달 창 중앙에 맞추기 문제 아래 css를 이용하여 중앙 배치를 하였는데 모달이 중앙 살짝 우측으로 배치되지 않는 문제가 있다. position: fixed; top: 50%; left: 50%; 원인 50%로 고정되는 위치가 모달에 중앙이 아닌 좌측최상단이기때문에 발생하는 에러이다. 해결법 translate 를 이용하여서 모달 중앙으로 위치를 맞춰준다 transform: translate(-50%, -50%); 추가내용 -webkit-transform: translate(-50%, -50%); -moz-transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); -o-transform: translate(-50%, -50%); tran..
BOJ_12904: A와 B HTML 삽입 미리보기할 수 없는 소스 문제 링크 https://www.acmicpc.net/problem/12904 12904번: A와 B 수빈이는 A와 B로만 이루어진 영어 단어가 존재한다는 사실에 놀랐다. 대표적인 예로 AB (Abdominal의 약자), BAA (양의 울음 소리), AA (용암의 종류), ABBA (스웨덴 팝 그룹)이 있다. 이런 사실에 놀란 수 www.acmicpc.net 핵심 문제의 핵심은 역순으로 시작하는 것이다. 정순으로 bfs를 이용하여 진행할 경우 시간 초과가 발생한다. 이 경우 케이스가 두 가지밖에 없기에 역순으로 T에서 시작하여서 S가 나오면 답이었다. code start_word = input() end_word = input() is_answer = 0 def m..
boj_2839_설탕 배달 https://www.acmicpc.net/problem/2839 2839번: 설탕 배달 상근이는 요즘 설탕공장에서 설탕을 배달하고 있다. 상근이는 지금 사탕가게에 설탕을 정확하게 N킬로그램을 배달해야 한다. 설탕공장에서 만드는 설탕은 봉지에 담겨져 있다. 봉지는 3킬로그 www.acmicpc.net 문제 포인트 문제의 핵심은 두 변수가 서로의 영향을 주면서 변하다는 것이다. 그래서 큰 변수를 기준으로 변경하며 풀었다. 그리디하게 풀었지만 DP로 풀면 시간이 훨씬 아껴질 거 같다. code n = int(input()) five_bags = int(n//5) reminders = n - five_bags*5 if reminders %3 == 0: print(five_bags+int(reminders//3..