add: descriptions
This commit is contained in:
parent
ad962f2376
commit
6267755973
|
|
@ -19,6 +19,11 @@ ListNode* construct(int x, Ts... xs) {
|
|||
return new ListNode(x, construct(xs...));
|
||||
}
|
||||
|
||||
/**
|
||||
* 24. Swap Nodes in Pairs
|
||||
* Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)
|
||||
*/
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
static ListNode* swapPairs(ListNode* head) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
/**
|
||||
* 688. Knight Probability in Chessboard
|
||||
* On an n x n chessboard, a knight starts at the cell (row, column) and attempts to make exactly k moves. The rows and columns are 0-indexed, so the top-left cell is (0, 0), and the bottom-right cell is (n - 1, n - 1).
|
||||
* A chess knight has eight possible moves it can make, as illustrated below. Each move is two cells in a cardinal direction, then one cell in an orthogonal direction.
|
||||
*/
|
||||
|
||||
class Solution {
|
||||
private:
|
||||
inline static constexpr int dX[] = {-2, -1, 1, 2, 2, 1, -1, -2};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,13 @@
|
|||
#include <vector>
|
||||
#include <cstdio>
|
||||
|
||||
/**
|
||||
* 39. Combination Sum
|
||||
* Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order.
|
||||
* The same number may be chosen from candidates an unlimited number of times. Two combinations are unique if the frequency of at least one of the chosen numbers is different.
|
||||
* It is guaranteed that the number of unique combinations that sum up to target is less than 150 combinations for the given input.
|
||||
*/
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
static std::vector<std::vector<int>> combinationSum(const std::vector<int>& candidates, int target, int prev = 0) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,18 @@
|
|||
#include <vector>
|
||||
|
||||
/**
|
||||
* 1791. Find Center of Star Graph
|
||||
* There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.
|
||||
* You are given a 2D integer array edges where each edges[i] = [ui, vi] indicates that there is an edge between the nodes ui and vi. Return the center of the given star graph.
|
||||
*/
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
static int findCenter(const std::vector<std::vector<int>>& edges) {
|
||||
return edges[0][(edges[0][0] == edges[1][0] || edges[0][0] == edges[1][1]) ? 0 : 1];
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
/**
|
||||
* 402. Remove K Digits
|
||||
* Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.
|
||||
*/
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
static std::string removeKdigits(const std::string& num, int k) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,16 @@
|
|||
#include <vector>
|
||||
#include <cstdio>
|
||||
|
||||
/**
|
||||
* 969. Pancake Sorting
|
||||
* Given an array of integers arr, sort the array by performing a series of pancake flips.
|
||||
* In one pancake flip we do the following steps:
|
||||
* Choose an integer k where 1 <= k <= arr.length.
|
||||
* Reverse the sub-array arr[0...k-1] (0-indexed).
|
||||
* For example, if arr = [3,2,1,4] and we performed a pancake flip choosing k = 3, we reverse the sub-array [3,2,1], so arr = [1,2,3,4] after the pancake flip at k = 3.
|
||||
* Return an array of the k-values corresponding to a sequence of pancake flips that sort arr. Any valid answer that sorts the array within 10 * arr.length flips will be judged as correct.
|
||||
*/
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
static std::vector<int> pancakeSort(std::vector<int>& arr) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,18 @@
|
|||
#include <vector>
|
||||
#include <cstdio>
|
||||
|
||||
/**
|
||||
* 1675. Minimize Deviation in Array
|
||||
* You are given an array nums of n positive integers.
|
||||
* You can perform two types of operations on any element of the array any number of times:
|
||||
* If the element is even, divide it by 2.
|
||||
* For example, if the array is [1,2,3,4], then you can do this operation on the last element, and the array will be [1,2,3,2].
|
||||
* If the element is odd, multiply it by 2.
|
||||
* For example, if the array is [1,2,3,4], then you can do this operation on the first element, and the array will be [2,2,3,4].
|
||||
* The deviation of the array is the maximum difference between any two elements in the array.
|
||||
* Return the minimum deviation the array can have after performing some number of operations.
|
||||
*/
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
static int minimumDeviation(const std::vector<int>& nums) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
/**
|
||||
* 1288. Remove Covered Intervals
|
||||
* Given an array intervals where intervals[i] = [li, ri] represent the interval [li, ri), remove all intervals that are covered by another interval in the list.
|
||||
* The interval [a, b) is covered by the interval [c, d) if and only if c <= a and b <= d.
|
||||
* Return the number of remaining intervals.
|
||||
*/
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
#include <vector>
|
||||
|
||||
/**
|
||||
* 344. 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.
|
||||
*/
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
static void reverseString(std::vector<char>& s) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue