본문 바로가기

전체 글

[Leetcode/파이썬] 46. Permutations PermutationsGiven an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. Example 1:Input: nums = [1,2,3]Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]Example 2:Input: nums = [0,1]Output: [[0,1],[1,0]]Example 3:Input: nums = [1]Output: [[1]] Constraints:1 -10 All the integers of nums are unique.class Solution: def permute(se.. 더보기
[Leetcode/파이썬] 130. Surrounded Regions Surrounded RegionsYou are given an m x n matrix board containing letters 'X' and 'O', capture regions that are surrounded:Connect: A cell is connected to adjacent cells horizontally or vertically.Region: To form a region connect every 'O' cell.Surround: The region is surrounded with 'X' cells if you can connect the region with 'X' cells and none of the region cells are on the edge of the board.T.. 더보기
[Leetcode/파이썬] 61. Rotate List Rotate ListGiven the head of a linked list, rotate the list to the right by k places. Example 1:Input: head = [1,2,3,4,5], k = 2Output: [4,5,1,2,3]Example 2:Input: head = [0,1,2], k = 4Output: [2,0,1] Constraints:The number of nodes in the list is in the range [0, 500].-100 0 9 # Definition for singly-linked list.# class ListNode:# def __init__(self, val=0, next=None):# self.val = va.. 더보기
[Leetcode/파이썬] 290. Word Pattern Word PatternGiven a pattern and a string s, find if s follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in s. Specifically:Each letter in pattern maps to exactly one unique word in s.Each unique word in s maps to exactly one letter in pattern.No two letters map to the same word, and no two words map to the sam.. 더보기
[Leetcode/파이썬] 129. Sum Root to Leaf Numbers Sum Root to Leaf NumbersYou are given the root of a binary tree containing digits from 0 to 9 only.Each root-to-leaf path in the tree represents a number.For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123.Return the total sum of all root-to-leaf numbers. Test cases are generated so that the answer will fit in a 32-bit integer.A leaf node is a node with no children. Example .. 더보기
[Leetcode/파이썬] 48. Rotate Image Rotate ImageYou are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation. Example 1:Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]Output: [[7,4,1],[8,5,2],[9,6,3]]Example 2:Input: matrix = [[5,1,9,11],[2,4,8,10].. 더보기
[Leetcode/파이썬] 20. Valid Parentheses Valid ParenthesesGiven a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of brackets.Open brackets must be closed in the correct order.Every close bracket has a corresponding open bracket of the same type. Example 1:Input: s = "()"Output: trueExample 2:Input: .. 더보기
[Leetcode/파이썬] 86. Partition List Partition ListGiven the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of the two partitions. Example 1:Input: head = [1,4,3,2,5,2], x = 3Output: [1,2,2,4,3,5]Example 2:Input: head = [2,1], x = 2Output: [1,2] Constraints:The number of nodes in the l.. 더보기