Eat Study Love

먹고 공부하고 사랑하라

DP 13

Longest Palindrome Substring [Final 기출]

사실 Palindrome 문제는 유형도 많고, DP를 이용해서 풀면 편하지만 너~무 짜친다. 아오 하기 싫어! Longest Palindrome Substring(이하 LPS) 문제를 2개 풀게 됐는데, 하나는 10초컷 / 하나는 30분을 고민해도 어렵다.. 쉬운 문제는 아래와 같다.def is_palindromic(s: str) -> bool: """ > input 's' - A string consisting of only lowercase English letters (1 return a boolean """ # WRITE YOUR CODE HERE n = len(s) left = 0 right = n-1 while left  그냥 input에 대해..

Coding_Practice 2025.01.07

Guess Number Higher or Lower II[Math,Dynamic Programming,Game Theory]

https://leetcode.com/problems/guess-number-higher-or-lower-ii/description/We are playing the Guessing Game. The game will work as follows:I pick a number between 1 and n.You guess a number.If you guess the right number, you win the game.If you guess the wrong number, then I will tell you whether the number I picked is higher or lower, and you will continue guessing.Every time you guess a wrong n..

Coding_Practice 2024.11.05

Trapping Rain Water[자주 나오는 물 채우기 DP문제][Array,Two Pointers,Dynamic Programming,Stack,Monotonic Stack]

https://leetcode.com/problems/trapping-rain-water/description/Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Example 1:Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]Output: 6Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rai..

Coding_Practice 2024.11.04

Longest Nice Substring[Hash Table,String,Divide and Conquer,Bit Manipulation,Sliding Window]

https://leetcode.com/problems/longest-nice-substring/description/A string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase. For example, "abABB" is nice because 'A' and 'a' appear, and 'B' and 'b' appear. However, "abA" is not because 'b' appears, but 'B' does not.Given a string s, return the longest substring of s that is nice. If there ..

Coding_Practice 2024.10.10

Majority Element[Array,Hash Table,Divide and Conquer,Sorting,Counting]

https://leetcode.com/problems/majority-element/description/Given an array nums of size n, return the majority element.The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Example 1:Input: nums = [3,2,3]Output: 3Example 2:Input: nums = [2,2,1,1,1,2,2]Output: 2 Constraints:n == nums.length1 -109  Follow-up: C..

Coding_Practice 2024.10.10

Best Time to Buy and Sell Stock II[M,Array,Dynamic Programming,Greedy]

https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/description/You 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 yo..

Coding_Practice 2024.08.20