이카's
반응형
article thumbnail
알고리즘 유형 별 정리
알고리즘 문제풀이 2023. 5. 24. 13:23

알고리즘 풀이 모음 알고리즘을 한번으로 공부하는 것은 어렵다. 마치 수학문제같다..! 한번으로 땡!이 아닌 여러번 풀어보고, 필요한 로직을 기억하고, 유형별로 풀어보는게 좋은 방법이라고 생각한다! 알고리즘을 유형별로 정리해보고, 필요한 로직을 기록하기 위한 포스팅을 시작한다! BOJ 유형별로 가장 많은 문제를 보유한 플렛폼 입출력 I/O가 조금 불편하긴 하지만, 문제 유형이 많아서 좋고, 다양한 것을 공부 할 수 있어서 메리트가 있다. Programmers 일단 문제가 길다. (== 이해하는데 어렵다. 특히 카카오 문제) 하지만 사고력을 키울 수 있는 문제가 많다. 또한 최근 문제가 많아져서 풀만한 것 같다. 또한, I/O에 대한 부분을 전혀 신경을 쓸 필요가 없다.

article thumbnail
알고리즘을 잘 풀기 위한 팁 - 구현편(feat. 유튜버 큰돌님)
알고리즘 문제풀이 2023. 5. 23. 21:31

알고리즘 어떻게 풀까? 구현 디버깅 (굳이 메모장 필요 X) 문제 도식화 쉬움2 보통1 꾸준히 타자속도 자주 나오는 로직은 외우자 실력이 조금 있다? ▶️▶️▶️ BOJ 실버 2문제, 골드 1문제 그렇지 않다? ▶️▶️▶️ BOJ 브론즈 2문제, 실버 1문제 찾는 방법 solved.ac 들어가서 검색 ▶️▶️▶️ ex) #implementation *s (구현 실버 문제) 예시 백준 14502 - 연구소 벽 3개 새운다. 1-1. 모든 경우의 수 체크 - 완전 탐색 바이러스 퍼트린다 안전 영역 count하는 것 필요 DFS 구현 처음부터 IDE에서 풀되, 자동완성 쓰지 말고, 직접 치는 연습을 해야한다. 구현문제의 많은 경우는 x1, y1, x2, y2로 네방향으로 벽을 치면서 구현하는 문제가 많다. 꼭..

[Algorithm] LeetCode #6 Maximum Product Subarray

Problems Maximum Product Subarray Medium Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product. The test cases are generated so that the answer will fit in a 32-bit integer. A subarray is a contiguous subsequence of the array. 인접한 원소들과 곱샘을 했을 때, 가장 큰 결과값을 반환 Example 1: Input: nums = [2,3,-2,4] Output: 6 Explanation..

[Algorithm] LeetCode #5 Maximum Subarray

Problems Maximum Subarray Easy Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. A subarray is a contiguous part of an array. Example 1: Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. Example 2: Input: nums = [1] Output: 1 Example 3: Input: nums = [5,4,-1,7,8] ..

[Algorithm] LeetCode #4 Product of Array Except Self

Problem 238 Product of Array Except Self Medium 12160 740 Add to List Share Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. You must write an algorithm that runs in O(n) time and without using the division operation. Exa..

[Algorithm] LeetCode #3 Contains Duplicate

Problems Contains Duplicate Easy 4591 953 Add to List Share Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1: Input: nums = [1,2,3,1] Output: true Example 2: Input: nums = [1,2,3,4] Output: false Example 3: Input: nums = [1,1,1,3,3,4,3,2,4,2] Output: true 문제 이해 굉장히 쉬운 문제다. 배열안에 중복되는 숫자가 있으면 True없으면..

[Algorithm] LeetCode #2 Best time to buy and sell stock

LeetCode - Best time to buy and sell stock Problems You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. Example..

[Algorithm] LeetCode #1 Two Sum solved

Brute Force 내 방식 def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(len(nums)): for j in range(i + 1 , len(nums)): if nums[i] + nums[j] == target: return [i, j] Other Method Two pass Hash Table def twoSum(self, nums: List[int], target: int) -> List[int]: talbe = {num: i for i, num in enumerate(nums)} for idx, num in enumerate(nums): if ((target - num) in table) and (idx ..

[Algorithm] 올림피아드 최대점수구하기 python

최대점수 구하기(DFS) 이번 정보올림피아드대회에서 좋은 성적을 내기 위하여 현수는 선생님이 주신 N개의 문제를 풀려고 합니다. 각 문제는 그것을 풀었을 때 얻는 점수와 푸는데 걸리는 시간이 주어지게 됩 니다. 제한시간 M안에 N개의 문제 중 최대점수를 얻을 수 있도록 해야 합니다. (해당문제는 해당시간이 걸리면 푸는 걸로 간주한다, 한 유형당 한개만 풀 수 있습니다.) ▣ 입력설명 첫 번째 줄에 문제의 개수N(1

[Node.js] 백준 #10828 스택 (실패 : 시간초과)
알고리즘 문제풀이/BOJ 2021. 7. 20. 23:51

let fs = require('fs'); let input = fs.readFileSync('/dev/stdin').toString().split('\n'); let stackCount = Number(input[0]); function solution() { let stack = []; let result = 0; function PUSH (num) { return stack.concat(num); }; function TOP() { if (stack.length === 0) { return -1; } else { result = stack.slice(-1, ); } return result; }; function SIZE () { return stack.length; }; function EMPTY..

[JavaScript] 스택 구현

class Stack { constructor () { this.stack = []; this.size = 0; } push(arg) { this.size++; this.stack = this.stack.concat(arg); } size() { return this.size; } pop() { if (this.stack.length === 0) { return -1 } const popNum = this.stack[this.size - 1]; this.stack = this.stack.slice(0, -1); this.size-- return popNum; } empty() { if (this.size === 0) { return 1; } else { return 0; } } top() { if (th..

[Algorithm]프로그래머스 체육복 #python #그리디
알고리즘 문제풀이 2021. 5. 17. 22:53

처음 문제 풀때는 어떻게 풀어야 할지 막막했다. 어떻게 순서를 정하고 풀어야 하는데 어디서 부터 손 댈지가 막막했다. 그래도 순서 적어가면서 풀어봤는데, 나름 풀만 했다! 또한 새로운 걸 배워서 적어 본다. lost, reserve = list(set(lost) - set(reserve)), list(set(reserve) - set(lost)) 차집합 개념이라고 생각하면 된다. a - b라고 생각 했을때, a에서 b를 빼고 나머지 a가 담긴다. 즉 앞 set() 기준이라는 소리! 이 개념만 알면 코드 몇줄은 쉽게 줄여진다! 또한, list.remove(변수) 를 쓰니까 쉬웠다... list에 담겨져 있는 것 하나를 어떻게 지울까 하다가 remove를 쓰면 된다는 말에한번 써봤는데, 정말 쉽게 풀었다....

반응형