본문 바로가기
728x90
반응형

leetcode23

Leetcode 5. Longest Palindromic Substring (Dynamic programming) 문제. 주어진 문자열 s에서 부분 문자열 중, 역순으로 읽어도 값이 같은 가장 긴 부분 문자열을 찾아서 반환하시오 https://leetcode.com/problems/longest-palindromic-substring/ Longest Palindromic Substring - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 첫 시도) 가장 첫 번째 아이디어는 어떤 과정으로 조건을 충족하는 부분문자열을 만들 수 있을까?였습니다. 그래서 고민을 통해 문자열의 길이.. 2022. 9. 16.
Leetcode 03.Longest Substring Without Repeating Characters 문제. 주어진 문자열에서 가장 긴 부분 문장열의 길이를 반환하는 코드를 작성하라 https://leetcode.com/problems/longest-substring-without-repeating-characters/ Longest Substring Without Repeating Characters - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 처음에 문제를 보고 저는 쉬운 문자열 문제인 줄 알았지만, 또 다시 해시문제임을 눈치채지 못한 ㅜㅠㅠㅠ 바보였습.. 2022. 9. 16.
Leetcode 02. Add Two Numbers https://leetcode.com/problems/add-two-numbers/ Add Two Numbers - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제. 2개의 linkedlist가 주어졌을 때 각 항목을 더한 결과값을 reverse order로 반환하는 코드를 짜라. Input: l1 = [2,4,3], l2 = [5,6,4] Output: [7,0,8] Explanation: 342 + 465 = 807. 모범 답안) class Solutio.. 2022. 9. 15.
Leet code #1 Two Sum > 수식의 역발상과 enumerate사용 문제. nums라는 array가 주어졌을 때, target 숫자의 합이 나오는 각 숫자의 순번(=인덱스)가 담긴 array를 반환하라 (단, 각 input에는 하나의 조합만 존재한다 -> 여러 조합이 가능한 경우 없음) Input: nums = [2,7,11,15], target = 9 Output: [0,1] Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. 처음 접근 > nums의 변수를 앞에서부터 하나씩 더해보면서 target을 충족하는 숫자의 index를 반환하면 되지 않을까? class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: answer = [] .. 2022. 9. 12.
Leet code #94 Binary Tree Inorder Traverse (DFS, BFS) 문제. 다음과 같은 Binary Tree가 주어졌을 때, 노드 값들의 inorder traversal 를 반환하는 코드를 짜라 # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right Discussion 섹션의 Andvary님의 그림을 보고 좀 이해가 갔는데요. preorder/inorder/postorder/bfs이던 이런 Binary tree와 관련된 노드를 순회하는 문제에서는 어떤 순서대로 돌아가는지 구간을 나누는게 포인트였습니다 예를 들어, 아래 그림에서 1,2,3,4,5가 가는 방향을 보면 preorder은 노드 > 왼쪽 다 돌.. 2022. 9. 10.
728x90
반응형