분류 전체보기 205

[LeetCode] 로봇이 체리 먹는 문제: 1463. Cherry Pickup II

https://leetcode.com/problems/cherry-pickup-ii/ Cherry Pickup II - 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 grid에서 경로를 선택하는 문제는 몇 번 풀었는데 이 문제는 경로를 선택하는 주체가 둘이다. 방법을 조금 고민하다 보면 두 로봇은 다음 row로 넘어갈 때 동시에 넘어가야 한다는 결론이 나온다. bottom-up방식을 선택했는데 여기에는 로봇이 하나인 경우처럼 선택할 수 있는 루트의 합계를 누적하..

알고리즘 2022.04.14

[LeetCode] 딕셔너리 알파벳 빈도수: 1255. Maximum Score Words Formed by Letters

https://leetcode.com/problems/maximum-score-words-formed-by-letters/ Maximum Score Words Formed by Letters - 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 collections.Count()를 사용해서 letters에 있는 알파벳들의 개수를 파악한다. 이를 count라고 할 때 words의 문자열을 확인할 때마다 count의 개수를 줄여나가야 한다. words의 문자열을 취해서..

알고리즘 2022.04.14

[LeetCode] Edit_distance 알고리즘 문제: 72. Edit Distance

https://leetcode.com/problems/edit-distance/ Edit Distance - 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 이 문제는 edit distance 알고리즘의 전형적인 예시이다. 한 문자열을 다른 문자열로 변환하는 데 필요한 최소 작업 수를 계산하는 문제이다. 예전에 푼 문제와 비슷한 듯하면서도 다른다. 2021.12.02 - [알고리즘] - [Python] 리트코드 583. Delete Operation for Two..

알고리즘 2022.04.14

[LeetCode] stack을 활용한 문제: 394. Decode String

https://leetcode.com/problems/decode-string/ Decode 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 스택 자료구조를 활용하기 적절한 문제이다. 숫자와 문자를 각각의 변수에 저장하고 있다가 여는 괄호를 만나면 스택에 담는다. 닫는 괄호를 만나면 저장해뒀던 숫자와 문자를 꺼낸다. 현재의 문자는 스택에서 꺼낸 숫자대로 반복해주고 스택에서 꺼낸 이전의 문자는 반복 없이 스트링 변수에 저장해준다. 주의해야 할 점은 ..

알고리즘 2022.04.08

[JavaScipt] 번들러란?

번들러? 번들러의 예시로 웹팩을 들 수 있다. 웹팩은 많이 사용되는 모듈 번들러 중 하나인데 번들러의 특징은 아래와 같다. 1. 의존성이 있는 모듈 코드를 하나(또는 여러 개) 파일로 만들어 주는 도구 2. 브라우저 환경에서 잘 실행될 수 있도록 가공해 주는 역할 번들러 사용 이전의 문제점 프로젝트가 커질수록 자바스크립트 파일 각각의 의존성과 코드 사이 순서를 보장하기 힘들다는 부작용을 초래했고 심할 경우 일부 파일의 문제가 전체 스크립트를 실행에 영향을 미치기도 한다. 자바스크립트 언어 사양에 신규 모듈 시스템인 ES Module이 포함되어 이제는 모듈 없이 자바스크립트로 코딩하기 힘들어졌다. 아직 모든 브라우저에서 ES Module을 사용할 수 있는 것은 아니기 때문에 브라우저에서 모듈을 사용하려면 ..

WEB 2022.04.07

[LeetCode] 114. Flatten Binary Tree to Linked List 2가지 방법으로 풀기(Recursion, Morris Traversal)

https://leetcode.com/problems/flatten-binary-tree-to-linked-list/ Flatten Binary Tree to Linked List - 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 root를 전위 순회하여 모든 노드를 오른쪽으로 배치하는 문제이다. 재귀로 푸는 방법과 morris traversal 알고리즘을 사용하는 방식 두 가지로 풀어보았다. [방법 1: recursion] 왼쪽과 오른쪽으로 나누어서 각 부분을..

알고리즘 2022.04.06

[LeetCode] quick sort 알고리즘: 215. Kth Largest Element in an Array

https://leetcode.com/problems/kth-largest-element-in-an-array/ Kth Largest Element in an 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 이 문제는 sort()를 사용하면 아주 간단히 풀 수 있지만 정렬 알고리즘 공부할 겸 quick sort 알고리즘을 구현하여서 풀었다. quick sort는 pivot 값을 정한 뒤 그 값보다 작은 값과 큰 값을 구분해서 왼쪽 오른쪽에 배치한 뒤..

알고리즘 2022.04.05

[LeetCode] matrix 90도 회전 알고리즘: 48. Rotate Image

https://leetcode.com/problems/rotate-image/submissions/ Rotate Image - 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 각 row를 거꾸로 정렬한 뒤 matrix를 왼쪽 위에서 오른쪽 아래 대각선으로 잘랐다고 생각하고 그 대각선을 기준으로 각 칸을 swap 해준다. class Solution: def rotate(self, matrix: List[List[int]]) -> None: matrix.reverse..

알고리즘 2022.04.04

[LeetCode] BFS: 127. Word Ladder (Python, JavaScript)

https://leetcode.com/problems/word-ladder/ Word Ladder - 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 처음에는 이 문제를 재귀로 풀려고 했었는데 메모리를 초과하는 문제가 있어서 잘못된 방법이란 걸 알게 되었다. 자료구조로 딕셔너리와 큐를 사용하였다. 딕셔너리에 wordList의 모든 단어들을 한 글자씩 *로 바꾼걸 키로 하여 밸류를 리스트로 추가해준다. ex) {*ot:'hot', 'dot', lot'} beginW..

알고리즘 2022.04.04

[LeetCode] 581. Shortest Unsorted Continuous Subarray

https://leetcode.com/problems/shortest-unsorted-continuous-subarray/ Shortest Unsorted Continuous Subarray - 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 정렬해야 하는 제일 앞 인덱스와 제일 끝 인덱스를 찾아주면 된다. start와 end 두 가지 변수를 사용해서 start에는 [start] > [start+1]가 되는 지점을 찾고 end는 반대를 찾아서 변수에 저장해준다. ..

알고리즘 2022.04.03