본문 바로가기

개발 공부/Algorithm

(11)
[LeetCode] 60. Can Place Flowers You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots.Given an integer array flowerbed containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return true if n new flowers can be planted in the flowerbed without violating the no-adjacent-flowers rule and false otherwise. My answer is t..
[LeetCode] 374. Guess Number Higher or Lower 374. Guess Number Higher or Lower We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess.You call a pre-defined API int guess(int num), which returns three possible results:-1: Your guess is higher than the number I picked ..
[LeetCode] 62. Unique Paths 62. Unique PathsThere is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or right at any point in time.Given the two integers m and n, return the number of possible unique paths that the robot can take to reach the bottom-right cor..
Permute Practice def permute(txt, src): if src == len(txt): return ["".join(txt)] seen = set() result = [] for i in range(src, len(txt)): if txt[i] in seen: continue seen.add(txt[i]) if src!=i: txt[src], txt[i] = txt[i], txt[src] result.extend(permute(txt, src+1)) if src!=i: txt[src], txt[i] = txt[i], txt[src] return result result = permute(lits(digits), 0)  - Bas..
[LeetCode] 17. Letter Combinations of a Phone Number 17. Letter Combinations of a Phone NumberGiven a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.  BacktrackingBacktracking is an algorithmic techniqe used for solving probl..
[LeetCode] 2390. Removing Stars From a String 2390 . Removing Stars From a String You are given a string s, which contains stars *.In one operation, you can:Choose a star in s.Remove the closest non-star character to its left, as well as remove the star itself.Return the string after all stars have been removed.Note:The input will be generated such that the operation is always possible.It can be shown that the resulting string will always b..
[LeetCode] 338. Counting Bits 435. Counting BitsGiven an integer n, return an array ans of length n +1 such that for each i (0   1. Problem UnderstandingThe problem asks us to count the number of 1s (set bits) in the binary representation of every integer from 0 to n. The result should be returned as an array where the value at index i represents the count of set bits in the binary representation of i. 2. Core Concepts' Bina..
[LeetCode] 435. Non-overlapping Intervals 435. Non-overlapping Intervals Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.Note that intervals which only touch at a point are non-overlapping. For example, [1, 2] and [2, 3] are non-overlapping.  1. 문제 상황주어진 구간에서 겹치는 구간을 최소화하려면 몇 개의 구간을 제거해야 하는지 묻는 문제.겹치지 않는..
it 취업을 위한 알고리즘 문제풀이 - 1. 코드 구현력 기르기 it 취업을 위한 알고리즘 문제풀이 - 1. 코드 구현력 기르기 1.1 1부터 N까지의 M의 배수합 #include using namespace std; int main() { int m, n; cin >> m >> n; int i, sum = 0; for (i = 1; i a >> b; for (int i = a; i 0 && pos < n && ch[pos] == 0) ch[pos] = 1; else { printf("NO\n"); return 0; } pre = now; } printf("YES\n"); return 0; } 1.25 석차 구하기 N명의 생의 수학점수가 입력되면 각 학생의 석차를 입력된 순서대로 출력하라 #include #include #include using namespace s..
알고리즘 문제 해결 전략 Part02. 알고리즘 분석 프로그래밍 대회에서 배우는 알고리즘 문제 해결 전략 Algorithmic PRoblem Solving Strategies Part02. 알고리즘 분석 개관 - 시간 : 알고리즘이 적은 시간을 사용한다는 것은 더 빠르게 동작한다는 이야기 따라서 알고리즘의 수행 속도와 특성을 분석하는 능력이 필요하다 - 공간 : 알고리즘이 더 적은 공간을 사용한다는 것은 더 적은 용량의 메모리를 사용한다는 것 이 두 기준은 서로 상충하는 경우가 많다 2부는 알고리즘의 속도를 분석하는 방법과 알고리즘의 정당성을 증명하는 기술들을 소개한다. Chap4. 알고리즘의 시간 복잡도 분석 4.1 도입 직관적인 방법은 각각을 프로그램으로 구현한 뒤 같은 입력에대해 두 프로그램의 수행 시간을 측정하는 것이지만, 수행 시간은 언어는 물론 ..