본문 바로가기

전체 글

[Leetcode/파이썬]122. Best Time to Buy and Sell Stock II Best Time to Buy and Sell Stock IIYou are given an integer array prices where prices[i] is the price of a given stock on the ith day.On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, you can buy it then immediately sell it on the same day.Find and return the maximum profit you can achieve. Example 1:Input: prices = [7.. 더보기
[Leetcode/파이썬]121. Best Time to Buy and Sell Stock Best Time to Buy and Sell StockYou 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. Example 1:Input: prices = [7,1.. 더보기
[Leetcode/파이썬]123. Best Time to Buy and Sell Stock III Best Time to Buy and Sell Stock IIIYou are given an array prices where prices[i] is the price of a given stock on the ith day.Find the maximum profit you can achieve. You may complete at most two transactions.Note: You may not engage in multiple transactions simultaneously (i.e., you must sell the stock before you buy again). Example 1:Input: prices = [3,3,5,0,0,3,1,4]Output: 6Explanation: Buy o.. 더보기
[Leetcode/파이썬]2. Add Two Numbers Add Two NumbersYou are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example 1:Input: l1 = [2,4,3], l2 = [5,6,4]Output: [7,0,8]Explana.. 더보기
[Leetcode/파이썬]637. Average of Levels in Binary Tree Average of Levels in Binary TreeGiven the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10-5 of the actual answer will be accepted. Example 1:Input: root = [3,9,20,null,null,15,7]Output: [3.00000,14.50000,11.00000]Explanation: The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11.Hence return [3, .. 더보기
[Leetcode/파이썬]67. Add Binary Add BinaryGiven two binary strings a and b, return their sum as a binary string. Example 1:Input: a = "11", b = "1"Output: "100"Example 2:Input: a = "1010", b = "1011"Output: "10101" Constraints:1 4a and b consist only of '0' or '1' characters.Each string does not contain leading zeros except for the zero itself.class Solution: def addBinary(self, a: str, b: str) -> str: decimal_a = de.. 더보기
[Leetcode/파이썬]244.Basic Calculator Basic CalculatorGiven a string s representing a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation.Note: You are not allowed to use any built-in function which evaluates strings as mathematical expressions, such as eval(). Example 1:Input: s = "1 + 1"Output: 2Example 2:Input: s = " 2-1 + 2 "Output: 3Example 3:Input: s = "(1+(4+5+2)-3)+(6+8)"Out.. 더보기
[백준/파이썬][Silver II] 수열 걷기 - 4929 [Silver II] 수열 걷기 - 4929문제 링크성능 요약메모리: 110888 KB, 시간: 104 ms분류구현제출 일자2025년 3월 6일 20:18:06문제 설명길이가 유한하고, 오름차순 순서로 되어있는 두 수열이 주어진다. 두 수열에 공통으로 들어있는 원소는 교차점으로 생각할 수 있다.아래는 두 수열과 교차점은 굵게 나타낸 것이다.수열 1 = 3 5 7 9 20 25 30 40 55 56 57 60 62수열 2 = 1 4 7 11 14 25 44 47 55 57 100이 두 수열은 다음과 같이 걸을 수 있다.두 수열중 하나의 첫 번째 원소에서 걷기를 시작한다. 걷는 것은 앞으로만 걸을 수 있다.교차점에 도착했을 때는, 현재 수열에서 계속 걸을지, 다른 수열로 갈아탈지 결정할 수 있다.방문한 수의.. 더보기