LeetCode
-
[LeetCode] 11. Container With Most Water (JAVA)Algorithm 2023. 8. 26. 17:51
You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that you may not slant the container. Example 1: Input: height..
-
[Leetcode] 8. String To Integer(atoi) TypescriptAlgorithm 2023. 1. 24. 15:29
Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function). The algorithm for myAtoi(string s) is as follows: Read in and ignore any leading whitespace. Check if the next character (if not already at the end of the string) is '-' or '+'. Read this character in if it is either. This determines if the final result is negative or p..
-
[Leetcode] 5. Longest palindromic substring (Typescript)Algorithm 2022. 2. 1. 16:37
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 { while (lIndex >= 0 && rIndex { const evenPalindrome = checkPalindrome(i, i + 1); const oddPalindrome = checkPalindrome(i, i + 2); const values = [longestPalindrome, evenPalindrome, oddPal..
-
[leetcode] 4. Median of Two Sorted Arrays (Typescript)Algorithm 2021. 2. 21. 13:59
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. Follow up: The overall run time complexity should be O(log (m+n)). Example 1: Input: nums1 = [1,3], nums2 = [2] Output: 2.00000 Explanation: merged array = [1,2,3] and median is 2. Example 2: Input: nums1 = [1,2], nums2 = [3,4] Output: 2.50000 Explanation: merged array = [1,2,3,4] an..
-
[leetcode] 3. Longest Substring Without Repeating Characters (Typescript)Algorithm 2021. 2. 20. 14:14
Given a string s, find the length of the longest substring without repeating characters Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2: Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. Example 3: Input: s = "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Notice that the answ..