본문 바로가기
728x90

Language/Java144

[Programmers | Java | 연습문제 풀이] 문자열을 정수로 바꾸기 - Solution with Integer.valueOf() KDT 실무형 스프링 백엔드 엔지니어 양성과정 6기 | Algorithm CODEKATA🔁 문자열을 정수로 바꾸기🏷 관련 주제 : 형 변환 문자열 정수문제 설명문자열 s를 숫자로 변환한 결과를 반환하는 함수, solution을 완성하세요.제한 조건s의 길이는 1 이상 5이하입니다.s의 맨앞에는 부호(+, -)가 올 수 있습니다.s는 부호와 숫자로만 이루어져있습니다.s는 "0"으로 시작하지 않습니다.입출력 예예를들어 str이 "1234"이면 1234를 반환하고, "-1234"이면 -1234를 반환하면 됩니다.str은 부호(+,-)와 숫자로만 구성되어 있고, 잘못된 값이 입력되는 경우는 없습니다.✔ Solution with Integer.valueOf()class Solution { public i.. 2024. 6. 12.
[Programmers | Java | 정렬 문제 풀이] K번째 수 - Solution with copyOfRange() & sort() KDT 실무형 스프링 백엔드 엔지니어 양성과정 6기 | Algorithm CODEKATA🅰 K번째 수🏷 관련 주제 : 정렬 Arrays.sort Arrays.copyOfRange()문제 설명배열 array의 i번째 숫자부터 j번째 숫자까지 자르고 정렬했을 때, k번째에 있는 수를 구하려 합니다.예를 들어 array가 [1, 5, 2, 6, 3, 7, 4], i = 2, j = 5, k = 3이라면array의 2번째부터 5번째까지 자르면 [5, 2, 6, 3]입니다.1에서 나온 배열을 정렬하면 [2, 3, 5, 6]입니다.2에서 나온 배열의 3번째 숫자는 5입니다.배열 array, [i, j, k]를 원소로 가진 2차원 배열 commands가 매개변수로 주어질 때, commands의 모든 원소에 대해 .. 2024. 6. 12.
[LeetCode | Java | Binary Search 문제 풀이] 1351. Count Negative Numbers in a Sorted Matrix - Solution with Loop 99 Club 2기 | Java | Beginner📉 1351. Count Negative Numbers in a Sorted Matrix🏷 관련 주제 : Array Binary Search Matrix Algorithm ComplexityEasyGiven a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.Example 1:Input: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]Output: 8Explanation: There are 8 negative.. 2024. 6. 12.
[Programmers | Java | 연습 문제 풀이] x만큼 간격이 있는 n개의 숫자 - Solution with Loop KDT 실무형 스프링 백엔드 엔지니어 양성과정 6기 | Algorithm CODEKATA🔢 x만큼 간격이 있는 n개의 숫자🏷 관련 주제 : Loop long 연산자문제 설명함수 solution은 정수 x와 자연수 n을 입력 받아, x부터 시작해 x씩 증가하는 숫자를 n개 지니는 리스트를 리턴해야 합니다.다음 제한 조건을 보고, 조건을 만족하는 함수, solution을 완성해주세요.제한 조건x는 -10000000 이상, 10000000 이하인 정수입니다.n은 1000 이하인 자연수입니다.입출력 예xnanswer25[2,4,6,8,10]43[4,8,12]-42[-4, -8]✔ Solution with Loopclass Solution { public long[] solution(int x, int .. 2024. 6. 12.
[LeetCode | Java | Binary Search 문제 풀이] 35. Search Insert Position - Solution with Binary Search 99 Club 2기 | Java | Beginner📥 35. Search Insert Position🏷 관련 주제 : Array Binary SearchEasyGiven 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.Example 1:Input: nums = [1,3,5,6], target = 5Output: 2Example 2:Input: .. 2024. 6. 10.
[Programmers | Java | 월간 코드 챌린지 시즌3 문제 풀이] 나머지가 1이 되는 수 찾기 - Solution with Loop & Arithmetic Operator KDT 실무형 스프링 백엔드 엔지니어 양성과정 6기 | Algorithm CODEKATA➗ 나머지가 1이 되는 수 찾기🏷 관련 주제 : 반복문 연산자 나머지 연산자 조건문문제 설명자연수 n이 매개변수로 주어집니다.n을 x로 나눈 나머지가 1이 되도록 하는 가장 작은 자연수 x를 return 하도록 solution 함수를 완성해주세요.답이 항상 존재함은 증명될 수 있습니다.제한사항3 ≤ n ≤ 1,000,000입출력 예nresult1031211입출력 예 설명입출력 예 #110을 3으로 나눈 나머지가 1이고, 3보다 작은 자연수 중에서 문제의 조건을 만족하는 수가 없으므로, 3을 return 해야 합니다.입출력 예 #212를 11로 나눈 나머지가 1이고, 11보다 작은 자연수 중에서 문제의 조건을 만족하는.. 2024. 6. 10.
[LeetCode | Java | 동적 계획법 문제 풀이] 1025. Divisor Game - Solution with Brainteaser 99 Club 2기 | Java | Beginner➗ 1025. Divisor Game🏷 관련 주제 : Math Dynamic Programming Brainteaser Game TheoryEasyAlice and Bob take turns playing a game, with Alice starting first.Initially, there is a number n on the chalkboard.On each player's turn, that player makes a move consisting of:Choosing any x with 0 and n % x == 0.Replacing the number n on the chalkboard with n - x.Also, if a player c.. 2024. 6. 9.
[Programmers | Java | 연습 문제 풀이] 약수의 합 - Solution with Loop & Arithmetic Operator KDT 실무형 스프링 백엔드 엔지니어 양성과정 6기 | Algorithm CODEKATA➕ 약수의 합🏷 관련 주제 : 반복문 조건문 나머지 연산자 덧셈 연산자문제 설명정수 n을 입력받아 n의 약수를 모두 더한 값을 리턴하는 함수, solution을 완성해주세요.제한 사항n은 0 이상 3000이하인 정수입니다.입출력 예nreturn122856입출력 예 설명입출력 예 #112의 약수는 1, 2, 3, 4, 6, 12입니다. 이를 모두 더하면 28입니다.입출력 예 #25의 약수는 1, 5입니다. 이를 모두 더하면 6입니다.✔ Solution with Loop & Arithmetic Operator class Solution { public int solution(int n) { i.. 2024. 6. 9.
[LeetCode | Java | 동적 계획법 문제 풀이] 509. Fibonacci Number - Solution with Recursion 99 Club 2기 | Java | Beginner🔄️ 509. Fibonacci Number🏷 관련 주제 : Math Dynamic Programming Recursion MemorizationEasyThe Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,F(0) = 0, F(1) = 1F(n) = F(n - 1) + F(n - 2), for n > 1.Given n, calculate F(n).Example 1:Input: n .. 2024. 6. 8.
728x90