코딩 테스트(JAVA)(89)
-
[LeetCode] 785. Is Graph Bipartite?
https://leetcode.com/problems/is-graph-bipartite/description/ Is Graph Bipartite? - LeetCode Can you solve this real interview question? Is Graph Bipartite? - There is an undirected graph with n nodes, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. Mo leetcode.com 각 노드의 번호가 0에서 n-1 사이인 노드가 n개인 방향성 없..
2024.01.15 -
[programmers] 양과 늑대
https://school.programmers.co.kr/learn/courses/30/lessons/92343 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 2진 트리 모양 초원의 각 노드에 늑대와 양이 한 마리씩 놓여 있습니다. 이 초원의 루트 노드에서 출발하여 각 노드를 돌아다니며 양을 모으려 합니다. 각 노드를 방문할 때마다 해당 노드에 있던 양과 늑대가 당신을 따라오게 됩니다. 이때, 늑대는 양을 잡아먹을 기회를 노리고 있으며, 당신이 모은 양의 수보다 늑대의 수가 같거나 더 많아지면 바로 모든 양을 잡아먹어 버립니다. 당신은 중간에 양이 늑대..
2024.01.15 -
[LeetCode] 32. Longest Valid Parentheses
https://leetcode.com/problems/longest-valid-parentheses/description/ Longest Valid Parentheses - LeetCode Can you solve this real interview question? Longest Valid Parentheses - Given a string containing just the characters '(' and ')', return the length of the longest valid (well-formed) parentheses substring. Example 1: Input: s = "(()" Output: 2 Explanat leetcode.com Given a string containing..
2024.01.15 -
[programmers] 두 큐 합 같게 만들기
https://school.programmers.co.kr/learn/courses/30/lessons/118667 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 설명 길이가 같은 두 개의 큐가 주어집니다. 하나의 큐를 골라 원소를 추출(pop)하고, 추출된 원소를 다른 큐에 집어넣는(insert) 작업을 통해 각 큐의 원소 합이 같도록 만들려고 합니다. 이때 필요한 작업의 최소 횟수를 구하고자 합니다. 한 번의 pop과 한 번의 insert를 합쳐서 작업을 1회 수행한 것으로 간주합니다. 큐는 먼저 집어넣은 원소가 먼저 나오는 구조입니다. 이 문제..
2024.01.15 -
[LeetCode] 131. Palindrome Partitioning
문제 https://leetcode.com/problems/palindrome-partitioning/description/
2024.01.08 -
등비수열의 합
class Solution { public int solution(int n) { int firstTerm = 1; // 첫 항 int commonRatio = 2; // 공비 int sum = calculateGeometricSeriesSum(firstTerm, commonRatio, n); int moduloSum = sum % 1_000_000_007; return moduloSum; } // 등비수열의 합 계산 함수 public int calculateGeometricSeriesSum(int firstTerm, int commonRatio, int n) { int MOD = 1_000_000_007; int sum = 0; int currentTerm = firstTerm; for (int i =..
2023.08.27