LeetCode(4)
-
[LeetCode] [Medium] Longest Palindromic Substring (dp)
1. Problem Given s string and find longest palindromic substring 2. base: len find palindromic based len: s.size() ~ 1 bottom-up: iteration start => 1 -> s.size() You have to do unnecessary nested calculation. and must use dp algorithm. top-down: i teration start => s.size() -> 1 If find palindromic, immediately return substring. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 class Solution { public:..
2021.03.20 -
[LeetCode] [Medium] Longest Substring Without Repeating Characters
1. Problems Given a string. Find max length of substring without repeating characters. 2. sol I check all ascii for int array. Visited array has index of first finded index. and if find repeating char, Initialize all elements in front of first fineded index. This time complexity is O(N) because inner for statement operate total maximum n. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ..
2021.03.18 -
[LeetCode] [Medium] Add Two Numbers (linked list)
1. Problems Given two num list Add the two numbers and return the sum 2. Sol I use triple pointer for update double pointer. Becuse double pointer have address of answer list and I don't want to change value of answer list. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 /** * Definition for singly-linked list. * struct ListNode { * int val; * L..
2021.03.17 -
[LeetCode] [easy] Two Sum (brute-force, map)
1. Problem Given: numbers array and target. Select two element and sum, if output is target return these index. 2. brute-force time-complexity of brute-force is O(N^2) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class Solution { public: vector twoSum(vector& nums, int target) { for(int i = 0; i
2021.03.16