본문 바로가기

Algorithm/Math

(97)
(C++) - LeetCode (easy) 1518. Water Bottles https://leetcode.com/problems/count-odd-numbers-in-an-interval-range/description/ 간단 산수 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 정답 변수 ans를 선언해 줍니다. 📔 풀이과정 1. low와 high 사이에는 high - low만큼의 간극이 존재하며 (high - low) / 2개의 홀수가 존재합니다. 2. 따라서 ans의 초기값은 (high - low) / 2에서 low 또는 hight가 홀수라면 ans에 한 개씩 더해주면 됩니다. 📔 정답 출력 | 반환 ans를 반환합니다. 📕 Code 📔 C++ class Solution { public: int countOdds(int low, int high) { int ans = (hi..
(C++) - LeetCode (easy) 1207. Unique Number of Occurrences https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position/ Minimum Cost to Move Chips to The Same Position - LeetCode Can you solve this real interview question? Minimum Cost to Move Chips to The Same Position - We have n chips, where the position of the ith chip is position[i]. We need to move all the chips to the same position. In one step, we can change the position of lee..
(C++) - LeetCode (easy) 1037. Valid Boomerang https://leetcode.com/problems/valid-boomerang/description/ Valid Boomerang - LeetCode Can you solve this real interview question? Valid Boomerang - Given an array points where points[i] = [xi, yi] represents a point on the X-Y plane, return true if these points are a boomerang. A boomerang is a set of three points that are all distinct and leetcode.com 직선의 기울기를 이용한 문제였습니다. 📕 풀이방법 📔 풀이과정 📕 Code 📔..
(C++) - LeetCode (easy) 1025. Divisor Game https://leetcode.com/problems/divisor-game/description/ LeetCode - The World's Leading Online Programming Learning Platform 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 < x < n 며 n의 인수 x 중에서 최적으로 정답을 고르는 경우는 1을 고르는 것입니다.서로 1을 고르게 된다면 최종적으로 1이 남으면 그 사람이 지므로 짝수인 ..
(C++, Rust) - LeetCode (easy) 914. X of a Kind in a Deck of Cards https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/description/ X of a Kind in a Deck of Cards - LeetCode Can you solve this real interview question? X of a Kind in a Deck of Cards - You are given an integer array deck where deck[i] represents the number written on the ith card. Partition the cards into one or more groups such that: * Each group has exactly x leetcode.com 최대공약수를 이용한 문제..
(C++) - LeetCode (easy) 367. Valid Perfect Square https://leetcode.com/problems/valid-perfect-square/description/ Valid Perfect Square - LeetCode Can you solve this real interview question? Valid Perfect Square - Given a positive integer num, return true if num is a perfect square or false otherwise. A perfect square is an integer that is the square of an integer. In other words, it is the product o leetcode.com 가우스의 제곱합 공식을 이용한 문제였습니다. 📕 풀이방법 ..
(C++) - LeetCode (easy) 231. Power of Two https://leetcode.com/problems/power-of-two/description/ Power of Two - LeetCode Power of Two - Given an integer n, return true if it is a power of two. Otherwise, return false. An integer n is a power of two, if there exists an integer x such that n == 2x. Example 1: Input: n = 1 Output: true Explanation: 20 = 1 Example 2: Input: n leetcode.com 수학 관련 함수를 사용해보는 문제였습니다. 📕 풀이방법 📔 풀이과정 1. log를 씌운다고 ..
(Python) - 백준(BOJ) 22938 : 백발백준하는 명사수 https://www.acmicpc.net/problem/22938 22938번: 백발백준하는 명사수 백발백준은 무슨 과녁이던 백발백중하여 올림픽 금메달보다 따기 어렵다는 대한민국 양궁 국가대표 타이틀을 가지고 있다. 이런 백발백준이 현재 연마하는 스킬이 있는데... 바로 두 과녁을 www.acmicpc.net 원의 성질을 이용하는 문제였습니다. 📕 풀이방법 📔 입력 및 초기화 info, info2 선언 후 한 원의 중심 (x, y) 좌표와, 원의 반지름 r을 list형태로 입력받습니다.두 반지름의 합은 total_radian에, 원 좌표 사이의 거리를 구해 dist에 저장합니다. 📔 풀이과정 10^9까지의 범위이므로 좌표 사이의 거리로 제곱값을 구해야하는 상황에서 overflow가 납니다. 사직연산에 ..