프로그래밍/algorithm
-
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..
-
leetCode (Remove Linked List Elements)-LinkedList프로그래밍/algorithm 2021. 7. 6. 11:59
문제 Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head. Example 1: Input: head = [1,2,6,3,4,5,6], val = 6 Output: [1,2,3,4,5] 배경지식 연결리스트 - 원소들을 저장할 때, 그 다음 원소가 있는 위치를 포함시키는 방식으로 저장하는 자료구조. 특징 k번째 원소를 확인/변경하기 위해 O(k(가 필요함 임의의 위치에 원소를 추가/임의 위치의 원소 제거는 O(1) 원소들이 메모리 상에 연속해 있지 않아 Cache hit rate가 낮지만 할당이 다소 쉬움 문..
-
leetCode - Intersection of Two Linked Lists (LinkedList)프로그래밍/algorithm 2021. 7. 6. 09:46
문제 Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null. For example, the following two linked lists begin to intersect at node c1: It is guaranteed that there are no cycles anywhere in the entire linked structure. Note that the linked lists must retain their original structu..