본문 바로가기
728x90

Algorithm75

[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] 46. Permutations Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. Example 1: Input: nums = [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] Example 2: Input: nums = [0,1] Output: [[0,1],[1,0]] Example 3: Input: nums = [1] Output: [[1]] Constraints: 1 2023. 11. 9.
[LeetCode] 45. Jump Game II You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0]. Each element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at nums[i], you can jump to any nums[i + j] where: 0 2023. 11. 9.
728x90