본문 바로가기

분류 전체보기88

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 sel.. 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.
[Programmers] 해시.전화번호 목록 https://school.programmers.co.kr/learn/courses/30/lessons/42577 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 어려운 문제는 아니고 간단하지만 약간의 고민이 필요한 문제 (그냥 풀면 효율성 채점에서 틀림) import java.util.*;class Solution { public boolean solution(String[] phone_book) { Set set = new HashSet(); Set original = new HashSet(); for (String str : phone_book) { .. 2025. 4. 20.
[Programmers] 해시.폰켓몬 / HashMap 과 collectingAndThen https://school.programmers.co.kr/learn/courses/30/lessons/1845 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 자체는 매우 간단한데, 다른 풀이가 인상깊어서 포스팅 합니다. 내 풀이import java.util.HashSet;import java.util.Set;class Solution { public int solution(int[] nums) { Set set = new HashSet(); for (int num : nums) { set.add(num); } .. 2025. 4. 16.
Runnable과 Callable의 차이 특징RunnableCallable반환값없음 (void)값 반환 (V)예외 처리검사 예외(Checked Exception) 명시 불가검사 예외 명시 가능 (throws Exception)주요 메서드void run()V call()사용 목적단순히 작업 실행작업 실행 후 결과 반환, 예외 처리 필요 시Runnable과 Callable의 예외 처리 관점에서의 차이는 두 인터페이스의 메서드가 검사 예외(Checked Exception)를 어떻게 처리하는지와 관련이 있습니다.1. 검사 예외와 비검사 예외검사 예외 (Checked Exception)Java 컴파일러가 명시적으로 처리하도록 요구하는 예외.예: IOException, SQLException, InterruptedException.메서드에서 던지려면 th.. 2025. 1. 18.