java 30

[LeetCode] 110. Balanced Binary Tree

110. Balanced Binary TreeLeetCode Given a binary tree, determine if it is height-balanced.이진 트리(Binary Tree)가 주어졌을 때, 해당 트리가 높이 균형(Height-balanced)이 잡힌 상태인지 판별하세요. ExampleInput: root = [3,9,20,null,null,15,7]Output: trueInput: root = [1,2,2,3,3,null,null,4,4]Output: falseInput: root = [] Output: true1. 문제 요구사항 분석균형이진트리인지 묻는 문제: 노드의 높이가 2이상 차이나면 균형이진트리 조건 불충분2. 접근 전략DFS로 구현하기import java.util.*;cl..

[LeetCode] 424. Longest Repeating Character Replacement

424. Longest Repeating Character ReplacementLeetCode You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times.Return the length of the longest substring containing the same letter you can get after performing the above operations.문자열 s와 정수 k가 주어집니다. 문자열 내에서 임의의 문자를 ..

[LeetCode] 338. Counting Bits

338. Counting BitsLeetCode Given an integer n, return an array ans of length n + 1 such that for each i (0 정수 n이 주어졌을 때, 0 ExampleInput: n = 2 Output: [0,1,1] Explanation: 0 --> 0 1 --> 1 2 --> 10Input: n = 5 Output: [0,1,1,2,1,2] Explanation: 0 --> 0 1 --> 1 2 --> 10 3 --> 11 4 --> 100 5 --> 1011. 문제 요구사항 분석0 ~ n 까지 이진수로 표현한 후, 1의 개수 구하기 2. 접근 전략파이썬은 bin이라고 제공되고 있는 함수가 있기 때문에 파이썬으로 1차 구현 후, 자바..

[LeetCode] 73. Set Matrix Zeroes

73. Set Matrix ZeroesLeetCode Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's.m X n 크기의 정수 행렬 matrix가 주어질 때, 특정 원소가 0이라면 해당 원소가 속한 행과 열의 모든 원소를 0으로 설정하십시오. ExampleInput: matrix = [[1,1,1],[1,0,1],[1,1,1]] Output: [[1,0,1],[0,0,0],[1,0,1]] Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]] Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]1. 문제 요구사항 분석0 원소 상하좌우를 0..

[LeetCode] 191. Number of 1 Bits

191. Number of 1 BitsLeetCodeGiven a positive integer n, write a function that returns the number of set bits in its binary representation (also known as the Hamming weight).양의 정수 n이 주어졌을 때, 해당 숫자의 이진수 표현에서 '설정된 비트(set bits, 값이 1인 비트)'의 개수를 반환하는 함수를 작성하세요 (이는 해밍 가중치(Hamming weight)라고도 부릅니다). ExampleInput: n = 11Output: 3Explanation:The input binary string 1011 has a total of three set bits.Input..

[LeetCode] 70. Climbing Stairs

70. Climbing StairsLeetCodeYou are climbing a staircase. It takes n steps to reach the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?당신은 계단을 오르고 있습니다. 꼭대기에 도달하려면 n개의 계단을 올라야 합니다.한 번에 1계단 또는 2계단씩 오를 수 있습니다. 꼭대기까지 오르는 서로 다른 방법은 총 몇 가지입니까? ExampleInput: n = 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 ..

728x90
반응형