[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 함수를..
[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() {}..
[99클럽] 99클럽 코테 스터디 13일차 TIL - DFS/BFS
·
코딩테스트 연습/99클럽
오늘의 문제LeetCode - Evaluate Boolean Binary Tree (출처 하단 표기) 문제You are given the root of a full binary tree with the following properties:Leaf nodes have either the value 0 or 1, where 0 represents False and 1 represents True.Non-leaf nodes have either the value 2 or 3, where 2 represents the boolean OR and 3 represents the boolean AND.The evaluation of a node is as follows:If the node is a leaf nod..
[99클럽] 99클럽 코테 스터디 12일차 TIL - DFS/BFS
·
코딩테스트 연습/99클럽
오늘의 문제LeetCode - Find a Corresponding Node of a Binary Tree in a Clone of That Tree (출처 하단 표기) 문제Given two binary trees original and cloned and given a reference to a node target in the original tree.The cloned tree is a copy of the original tree.Return a reference to the same node in the cloned tree.Note that you are not allowed to change any of the two trees or the target node and the answer m..
[99클럽] 99클럽 코테 스터디 11일차 TIL - DFS/BFS
·
코딩테스트 연습/99클럽
오늘의 문제LeetCode - Range Sum of BST (출처 하단 기재) 문제Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high]. 제한사항The number of nodes in the tree is in the range [1, 2 * 10 ⁴ ].1 1 All Node.val are unique.입출력 예rootlowhighreturn[10,5,15,3,7,null,18]71532[10,5,15,3,7,13,18,1,null,6]61023 풀이/** * Defi..