[99클럽] 99클럽 코테 스터디 22일차 TIL - 이분탐색 (Binary Search)
·
코딩테스트 연습/99클럽
오늘의 문제LeetCode - Search Insert Position (출처 하단 표기) 문제Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You must write an algorithm with O(log n) runtime complexity. 제한사항1 -10 ⁴  ⁴nums contains distinct values sorted in ascending order.-10 ⁴  ⁴입출력 예numstargetreturn[1, 3, 5,..
[99클럽] 99클럽 코테 스터디 21일차 TIL - 동적계획법 (Dynamic Programming)
·
코딩테스트 연습/99클럽
오늘의 문제백준 - 1로 만들기 (출처 하단 표기)원래 오늘 비기너 문제는 이 문제였지만 시간이 오래 걸리지 않아 다른 문제를 하나 더 풀었다. 문제정수 X에 사용할 수 있는 연산은 다음과 같이 세 가지이다.X가 3으로 나누어 떨어지면, 3으로 나눈다.X가 2로 나누어 떨어지면, 2로 나눈다.1을 뺀다.정수 N이 주어졌을 때, 위와 같은 연산 세 개를 적절히 사용해서 1을 만들려고 한다. 연산을 사용하는 횟수의 최솟값을 출력하시오. 입력첫째 줄에 1보다 크거나 같고, 10^6보다 작거나 같은 정수 N이 주어진다. 출력첫째 줄에 연산을 하는 횟수의 최솟값을 출력한다. 풀이import java.util.Scanner;public class Main { public static void main(..
[99클럽] 99클럽 코테 스터디 20일차 TIL - 동적계획법 (Dynamic Programming)
·
코딩테스트 연습/99클럽
오늘의 문제LeetCode - Partition Array for Maximum Sum (출처 하단 표기)비기너 문제가 쉬워서 미들러 문제도 같이 풀어보았다. 문제Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray.Return the largest sum of the given array after partitioning. Test cases are generated so that the answer ..
[99클럽] 99클럽 코테 스터디 19일차 TIL - 동적계획법 (Dynamic Programming)
·
코딩테스트 연습/99클럽
오늘의 문제LeetCode - Pascal's Triangle (출처 하단 표기) 문제Given an integer numRows, return the first numRows of Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it as shown: 제한사항1 입출력 예numRowsreturn5[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]1[[1]] 풀이초기 코드import java.util.*;class Solution { public List> generate(int numRows) { /* 파스칼의 삼각형 ..
[99클럽] 99클럽 코테 스터디 18일차 TIL - 동적계획법 (Dynamic Programming)
·
코딩테스트 연습/99클럽
오늘의 문제LeetCode - Counting Bits (출처 하단 표기) 문제Given an integer n, return an array ans of length n + 1 such that for each i (0 ), ans[i] is the number of 1's in the binary representation of i. 제한사항0 입출력 예nreturn2[0, 1, 1]5[0, 1, 1, 2, 1, 2] 풀이class Solution { public int[] countBits(int n) { // 2진수로 바꿨을 때 1의 개수 int[] answer = new int[n+1]; StringBuilder sb = new Strin..
[99클럽] 99클럽 코테 스터디 17일차 TIL - 그리디 (Greedy)
·
코딩테스트 연습/99클럽
오늘의 문제Leetcode - Split a String in Balanced Strings (출처 하단 표기) 문제Balanced strings are those that have an equal quantity of 'L' and 'R' characters.Given a balanced string s, split it into some number of substrings such that:Each substring is balanced.Return the maximum number of balanced strings you can obtain. 제한사항2 s[i] is either 'L' or 'R'.s is a balanced string.입출력 예sreturn"RLRRLLRLRL"4"RLRRR..
[99클럽] 99클럽 코테 스터디 16일차 TIL - 그리디 (Greedy)
·
코딩테스트 연습/99클럽
오늘의 문제프로그래머스 - 조이스틱 (출처 하단 기재)비기너 문제가 푼 문제라 미들러 문제를 풀었는데 아주 오랜 시간이 걸렸다... 문제조이스틱으로 알파벳 이름을 완성하세요. 맨 처음엔 A로만 이루어져 있습니다.ex) 완성해야 하는 이름이 세 글자면 AAA, 네 글자면 AAAA조이스틱을 각 방향으로 움직이면 아래와 같습니다.▲ - 다음 알파벳▼ - 이전 알파벳 (A에서 아래쪽으로 이동하면 Z로)◀ - 커서를 왼쪽으로 이동 (첫 번째 위치에서 왼쪽으로 이동하면 마지막 문자에 커서)▶ - 커서를 오른쪽으로 이동 (마지막 위치에서 오른쪽으로 이동하면 첫 번째 문자에 커서) 만들고자 하는 이름 name이 매개변수로 주어질 때, 이름에 대해 조이스틱 조작 횟수의 최솟값을 return 하도록 solution 함수를..
[자료구조] 트리 (Tree)
·
Computer Scrience/Data Structrue
트리 (Tree)트리는 원소들 간 일대다 관계를 가지는 비선형 자료구조이다. 다른 말로는 원소들 간 계층 관계를 가지는 계층형 자료구조이다. 따라서 트리는 부모와 자식 관계를 갖게 된다. 트리에서는 노드, 차수, 높이, 루트 노드, 리프 노드를 가지고 있는데 각각의 의미는 다음과 같다.노드(Node): 트리의 원소노드의 차수 (Degree): 노드에 연결된 자식 노드의 수. 가장 큰 값이 트리 전체의 차수가 된다.노드의 높이 (Height): 노드의 레벨이라고도 하며, 루트에서 노드에 이르는 간선의 수를 말한다. 이 역시 가장 큰 값이 트리의 높이가 된다.루트 노드 (Root Node): 부모가 없는 노드단말 노드 (Leaf Node): 자식이 없는 노드로 차수가 0인 노드트리는 차수에 따라 구분이 가능..
[99클럽] 99클럽 코테 스터디 15일차 TIL - DFS/BFS
·
코딩테스트 연습/99클럽
오늘의 문제LeetCode - Maximum Depth of Binary Tree (출처 하단 표기) 문제Given the root of a binary tree, return its maximum depth.A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 제한사항The number of nodes in the tree is in the range [0, 10⁴].-100 입출력 예rootreturn[3,9,20,null,null,15,7]3[1,null,2]2 풀이/** * Definition for a binary tree ..
[99클럽] 99클럽 코테 스터디 14일차 TIL - DFS/BFS
·
코딩테스트 연습/99클럽
오늘의 문제LeetCode - Invert Binary Tree (출처 하단 기재) 문제Given the root of a binary tree, invert the tree, and return its root. 제한사항The number of nodes in the tree is in the range [0, 100].-100 입출력 예rootreturn[4,2,7,1,3,6,9][4,7,2,9,6,3,1][2,1,3][2,3,1][ ][ ] 풀이/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {}..