전체 글
-
leetCode - Regular Expression Matching프로그래밍/algorithm 2021. 7. 19. 10:58
문제 Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where: '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). Example 1: Input: s = "aa", p = "a" Output: false Explanation: "a" does not match the entire string "aa". Example 2: Input: s ..
-
leetCode - Reverse Integer프로그래밍/algorithm 2021. 7. 19. 08:31
문제 Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0. Assume the environment does not allow you to store 64-bit integers (signed or unsigned). Example 1: Input: x = 123 Output: 321 Example 2: Input: x = -123 Output: -321 Example 3: Input: x = 120 Output: 21 Example 4: In..
-
leetCode - ZigZag Conversion프로그래밍/algorithm 2021. 7. 19. 07:44
문제 The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H N A P L S I I G Y I R And then read line by line: "PAHNAPLSIIGYIR" Write the code that will take a string and make this conversion given a number of rows: string convert(string s, int numRows); Example 1: Input: s = "..
-
leetCode - Longest Palindromic Substring(DP)프로그래밍/algorithm 2021. 7. 16. 10:47
문제 Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Note: "aba" is also a valid answer. Example 2: Input: s = "cbbd" Output: "bb" Example 3: Input: s = "a" Output: "a" Example 4: Input: s = "ac" Output: "a" Constraints: 1 = 0; i--) { for (let j = i + 2; j < s.length; j++) { dp[i][j] = dp[i + 1][j - 1] && s[i] === s[j]; if (dp[i][j]) lps..
-
leetCode-Median of Two Sorted Arrays(binary search)프로그래밍/algorithm 2021. 7. 15. 11:36
문제 Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. 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] and median..
-
leetCode - Longest Substring Without Repeating Characters(LinkedList)프로그래밍/algorithm 2021. 7. 14. 12:29
문제 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 ..
-
leeCode -Add Two Numbers(LinkedList)프로그래밍/algorithm 2021. 7. 14. 10:54
문제 You 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] Explanation: 34..
-
leetCode - Reverse Linked List(LinkedList)프로그래밍/algorithm 2021. 7. 7. 11:37
문제 Given the head of a singly linked list, return true if it is a palindrome. Example 1: Input: head = [1,2,2,1] Output: true Example 2: Input: head = [1,2] Output: false 배경지식 연결리스트 - 원소들을 저장할 때, 그 다음 원소가 있는 위치를 포함시키는 방식으로 저장하는 자료구조. 특징 k번째 원소를 확인/변경하기 위해 O(k(가 필요함 임의의 위치에 원소를 추가/임의 위치의 원소 제거는 O(1) 원소들이 메모리 상에 연속해 있지 않아 Cache hit rate가 낮지만 할당이 다소 쉬움 문제해결 slow, fast를 활용해서 주어진 head의 반을 가져오자 revers..