본문 바로가기

반응형

코딩 테스트

(98)
[LeetCode] 322. Coin Change 문제 leetcode.com/problems/coin-change/ Coin Change - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 잠깐만 0부터 코인들을 더해볼까요? 아니면, 목표 값에서 코인들을 하나씩 빼볼까요? 코드 22년 2월 17일 코드 class Solution { func coinChange(_ coins: [Int], _ amount: Int) -> Int { if amount == 0 { return 0 } var result = Arra..
[LeetCode] 70. Climbing Stairs 문제 leetcode.com/problems/climbing-stairs/ Climbing Stairs - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 코드 class Solution { func climbStairs(_ n: Int) -> Int { var before2 = 0 var before1 = 1 for i in 1...n { var current = before2 + before1 before2 = before1 before1 = current }..
[LeetCode] 190. Reverse Bits 문제 leetcode.com/problems/reverse-bits/ Reverse Bits - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 잠깐만 "If this function is called many times, how would you optimize it?" 문제는 풀어도 최적화가 관건이네요~ 코드 21년 4월 7일 코드 class Solution { func reverseBits(_ n: Int) -> Int { var calN = n var re..
[LeetCode] 268. Missing Number 문제 leetcode.com/problems/missing-number/ Missing Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 잠깐만 손으로 계산하면서 패턴을 찾아보세요 코드 class Solution { func missingNumber(_ nums: [Int]) -> Int { var totalSum = 0 var numSum = 0 for i in 0.. Int { var missingNum = 0 var addNum = 1 nums..
[LeetCode] 338. Counting Bits 문제 leetcode.com/problems/counting-bits/ Counting Bits - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 잠깐만 DP입니다 코드 22년 2월 16일 작성 코드 class Solution { func countBits(_ n: Int) -> [Int] { var oneCount: [Int] = Array(repeating: 0, count: n+1) if oneCount.count > 1 { oneCount[1] = 1 }..
[LeetCode] 191. Number of 1 Bits 문제 leetcode.com/problems/number-of-1-bits/ Number of 1 Bits - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 잠깐만 비트 연산으로 풀어보세요 코드 class Solution { func hammingWeight(_ n: Int) -> Int { var targetNum = n var count = 0 for i in 0..> 1 } return count } } 설명 비트 연산을 통해, 1의 개수를 계산했습니다.
[LeetCode] 371. Sum of Two Integers 문제 leetcode.com/problems/sum-of-two-integers/ Sum of Two Integers - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 잠깐만 비트 연산인데, 아이디어가 없으면 코드 바로 보세요~ 코드 class Solution { func getSum(_ a: Int, _ b: Int) -> Int { var tempB = (a & b)
DP - 14501. 퇴사 문제 www.acmicpc.net/problem/14501 14501번: 퇴사 첫째 줄에 백준이가 얻을 수 있는 최대 이익을 출력한다. www.acmicpc.net 코드 import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine..
DP - 9461. 파도반 수열 문제 www.acmicpc.net/problem/9461 9461번: 파도반 수열 오른쪽 그림과 같이 삼각형이 나선 모양으로 놓여져 있다. 첫 삼각형은 정삼각형으로 변의 길이는 1이다. 그 다음에는 다음과 같은 과정으로 정삼각형을 계속 추가한다. 나선에서 가장 긴 변의 www.acmicpc.net 잠깐만 삼각형의 한번이 어떤 값으로 이루어졌는지 확인하세요. 코드 import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws Exception { long[] lengths = ..
DP - 11727. 2×n 타일링 2 문제 www.acmicpc.net/problem/11727 11727번: 2×n 타일링 2 2×n 직사각형을 1×2, 2×1과 2×2 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오. 아래 그림은 2×17 직사각형을 채운 한가지 예이다. www.acmicpc.net 잠깐만 11726. 2xn 타일링 문제 풀어보셨나요? 유사한 문제니, 같은 방법으로 풀어보세요 skillist.tistory.com/226 DP - 11726. 2×n 타일링 문제 www.acmicpc.net/problem/11726 11726번: 2×n 타일링 2×n 크기의 직사각형을 1×2, 2×1 타일로 채우는 방법의 수를 구하는 프로그램을 작성하시오. 아래 그림은 2×5 크기의 직사각형을 채운 한 가지 방법 skillist.ti..

반응형