본문 바로가기
728x90

LeetCode78

[LeetCode] 5. Longest Palindromic Substring Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Explanation: "aba" is also a valid answer. Example 2: Input: s = "cbbd" Output: "bb" Constraints: 1 oddLength) { return acc; } else if (evenLength > oddLength) { // 현재까지의 최대값이 짝수 길이의 팰린드롬보다 작으면 업데이트 return s.substr(idx - evenOffset + 1, evenLength); } else { // 현재까지의 최대값이 홀수 길이의 팰린드롬보다 작으.. 2023. 11. 15.
[LeetCode] 50. Pow(x, n) Implement pow(x, n), which calculates x raised to the power n (i.e., x^n). Example 1: Input: x = 2.00000, n = 10 Output: 1024.00000 Example 2: Input: x = 2.10000, n = 3 Output: 9.26100 Example 3: Input: x = 2.00000, n = -2 Output: 0.25000 Explanation: 2^-2 = 1/2^2 = 1/4 = 0.25 Constraints: -100.0 < x < 100.0 -2^31 2023. 11. 10.
[LeetCode] 49. Group Anagrams Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Example 1: Input: strs = ["eat","tea","tan","ate","nat","bat"] Output: [["bat"],["nat","tan"],["ate","eat","tea"]] Example 2: Input: strs = [""] O.. 2023. 11. 10.
[LeetCode] 48. Rotate Image You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation. Example 1: Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [[7,4,1],[8,5,2],[9,6,3]] Example 2: Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,.. 2023. 11. 10.
728x90