- Today
- Total
목록leetcode (186)
작심삼일
문제 링크: https://leetcode.com/problems/spiral-matrix-ii/ 문제 Given a positive integer n, generate an n x n matrix filled with elements from 1 to $n^2$ in spiral order. 조건 1
문제 링크: https://leetcode.com/problems/shift-2d-grid/ 문제 Given a 2D grid of size m x n and an integer k. You need to shift the grid k times. In one shift operation: Element at grid[i][j] moves to grid[i][j + 1]. Element at grid[i][n - 1] moves to grid[i + 1][0]. Element at grid[m - 1][n - 1] moves to grid[0][0]. Return the 2D grid after applying shift operation k times. 조건 m == grid.length n == gr..
문제 링크: https://leetcode.com/problems/kth-largest-element-in-a-stream/ 문제 Design a class to find the $k^{th}$ largest element in a stream. Note that it is the $k^{th}$ largest element in the sorted order, not the $k^{th}$ distinct element. Implement KthLargest class: KthLargest(int k, int[] nums) Initializes the object with the integer k and the stream of integers nums. int add(int val) Appends t..
문제 링크: https://leetcode.com/problems/last-stone-weight/ 문제 You are given an array of integers stones where stones[i] is the weight of the ith stone. We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have weights x and y with x
문제 링크: https://leetcode.com/problems/3sum-with-multiplicity/ 문제 Given an integer array arr, and an integer target, return the number of tuples i, j, k such that i < j < k and arr[i] + arr[j] + arr[k] == target. As the answer can be very large, return it modulo 109 + 7. 조건 3
문제 링크: https://leetcode.com/problems/container-with-most-water/ 문제 You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. No..
문제 링크: https://leetcode.com/problems/swapping-nodes-in-a-linked-list/ 문제 You are given the head of a linked list, and an integer k. Return the head of the linked list after swapping the values of the $k^{th}$ node from the beginning and the $k^{th}$ node from the end (the list is 1-indexed). 조건 The number of nodes in the list is n. 1
문제 링크: https://leetcode.com/problems/reverse-string/ 문제 Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place with O(1) extra memory. 조건 1 None: N = len(s) H = N//2 for n in range(H): s[n], s[N-n-1] = s[N-n-1], s[n]