【스터디노트】/▶알고리즘문제풀기8 [Best Time to Buy and Sell Stock] 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 출처: https://leetcode.com/problems/best-time-to-buy-and-sell-st.. 2025. 3. 29. [Merge Two Sorted Lists] 출처:https://leetcode.com/problems/merge-two-sorted-lists/description/ You are given the heads of two sorted linked lists list1 and list2.Merge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists.Return the head of the merged linked list. 당신에게 두 개의 정렬된 연결 리스트 list1과 list2의 시작점(머리)가 주어집니다. 두 리스트를 하나의 정렬된 리스트로 병합하세요. 이 리스트는 처음 두 리스트의 노드들을.. 2025. 3. 27. [Valid Parentheses] 출처:https://leetcode.com/problems/valid-parentheses/description/Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of brackets.Open brackets must be closed in the correct order.Every close bracket has a corresponding open bracket of the same type.해석: 문자 '(.. 2025. 3. 26. [twoSum] 출처: 리트코드 grind75https://leetcode.com/problems/two-sum/description/해석:정수 배열 nums와 정수 target이 주어졌을 때, 두 숫자의 인덱스를 반환하세요. 이때 두 숫자를 더하면 target이 됩니다. 각 입력에는 정확히 하나의 해결책이 있다고 가정할 수 있으며, 동일한 요소를 두 번 사용해서는 안 됩니다.답은 어떤 순서로든 반환할 수 있습니다. Input: nums = [2,7,11,15], target = 9Output: [0,1]Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. public class Grind75_day1_TwoSum_problem { public stati.. 2025. 3. 26. [스택과 큐] 부분발췌: 보요 시바타, 번역 강민 이지스퍼블리싱, 『Do it! 자료구조와 함께 배우는 알고리즘 입문-자바 』,p.144~159) 큐: 인큐:데이터를 넣는 작업디큐: 데이터를 뺴는 작업배열로 큐를 만들면 데이터를 꺼낼때마다 요소를 움직여야해서 O(n)의 복잡도를 갖는다.링버퍼: 배열요소를 앞 으로 옮기지 않는 큐front: 인큐하는 데이터 가운데 맨앞요소의 인덱스 저장rear: 맨뒤에 넣은 요소하나뒤에 인덱스를 저장하는 필드capacity:큐의 최대용량생성자 intQueue: 큐 본체용 배열을 생성하기 위한 준비단계num =0 ,front =0 ,rear=0->매개변수 maxlen으로 전달받은 용량을 capacity에 복사->que 본체를 생성!이걸 tester에서 사용할때는 2025. 3. 26. [알고리즘] 위상정렬 위상정렬 = 답이 2개가 나올수도 있다.그래프-> 인접 리스트로 표현 -> 진입차수배열을 초기화한다. 2025. 2. 28. 이전 1 2 다음