반응형

Computer Science/LeetCode 5

[LeetCode] 371. Sum of Two Integers

Sum of Two Integers - LeetCodeBinary operation을 사용하는 기본 문제라고 한다. Given two integers a and b, return the sum of the two integers without using the operators + and -.Example 1:Input: a = 1, b = 2 Output: 3Example 2:Input: a = 2, b = 3 Output: 5첫 시도하지만 역시 또 time limit에 걸려버렸다. 역시 나야!class Solution: def getSum(self, a: int, b: int) -> int: while b != 0: _and = a & b _x..

[LeetCode] 70. Climbing Stairs

Climbing Stairs - LeetCode Dynamic Programming 문제 중 가장 쉬운 버전이다. 70. Climbing StairsYou 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?Example 1:Input: n = 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 stepsExample 2: Input: n = 3 Output: 3 Explan..

[LeetCode] 121. Best Time to Buy and Sell Stock

Best Time to Buy and Sell Stock - LeetCodeYou are given an array prices where prices[i] is the price of a given stock on the ith day.You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.이번에는 최대 이득을 볼 수 있는 주..

[LeetCode] 1. Two Sum

문제 링크: https://leetcode.com/problems/two-sum/description/ 문제는 다음과 같다.Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.complement 만드는 것 제외하면 별 방법이 떠오르지 않아서 그냥 brute force처럼 했는데, e..

반응형