algorithm/leetcode7 121. Best Time to Buy and Sell Stock 문제배열에서 주식을 구매하고, 팔았을 때 언제 가장 큰 수익을 낼 수 있는가? 에 대한 문제https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/?envType=study-plan-v2&envId=top-interview-150 문제 확인하기더보기더보기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 .. 2025. 12. 22. 169. Majority Element (feat. Boyer–Moore Voting Algorithm) 문제int 배열에서 가장 자주 등장하는 원소의 값을 리턴하는 문제arraySize / 2 값보다 자주 등장하는 원소가 있다고 가정한다. 최초 풀이법가장 쉬우나, 비효율적인 풀이 방법map을 사용해서 를 저장하고, 가장 자주 나온 값을 매번 갱신하면서 가장 자주 나온 값을 반환하도록 풀었다.import java.util.HashMap;import java.util.Map;class Solution { public int majorityElement(int[] nums) { Map map = new HashMap(); int maxValue = 1, maxKey = nums[0]; for (int num : nums) { if (map.cont.. 2025. 12. 20. 이전 1 2 다음