[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/파이썬] 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/파이썬] 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/파이썬] 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..
더보기