add: description
This commit is contained in:
parent
74f36ba498
commit
fd09252584
|
|
@ -1,5 +1,13 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 306. Additive Number
|
||||||
|
* An additive number is a string whose digits can form an additive sequence.
|
||||||
|
* A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the sequence must be the sum of the preceding two.
|
||||||
|
* Given a string containing only digits, return true if it is an additive number or false otherwise.
|
||||||
|
* Note: Numbers in the additive sequence cannot have leading zeros, so sequence 1, 2, 03 or 1, 02, 3 is invalid.
|
||||||
|
*/
|
||||||
|
|
||||||
class Solution {
|
class Solution {
|
||||||
private:
|
private:
|
||||||
inline static unsigned long long readStr(const char* const str, int L, int R) {
|
inline static unsigned long long readStr(const char* const str, int L, int R) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,11 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 67. Add Binary
|
||||||
|
* Given two binary strings a and b, return their sum as a binary string.
|
||||||
|
*/
|
||||||
|
|
||||||
class Solution {
|
class Solution {
|
||||||
public:
|
public:
|
||||||
static std::string addBinary(const std::string& a, const std::string& b) {
|
static std::string addBinary(const std::string& a, const std::string& b) {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,12 @@ struct TreeNode {
|
||||||
~TreeNode() { delete this->left; delete this->right; }
|
~TreeNode() { delete this->left; delete this->right; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 701. Insert into a Binary Search Tree
|
||||||
|
* You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.
|
||||||
|
* Notice that there may exist multiple valid ways for the insertion, as long as the tree remains a BST after insertion. You can return any of them.
|
||||||
|
*/
|
||||||
|
|
||||||
class Solution {
|
class Solution {
|
||||||
public:
|
public:
|
||||||
static TreeNode* insertIntoBST(TreeNode* root, int val) {
|
static TreeNode* insertIntoBST(TreeNode* root, int val) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 747. Largest Number At Least Twice of Others
|
||||||
|
* You are given an integer array nums where the largest integer is unique.
|
||||||
|
* Determine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of the largest element, or return -1 otherwise.
|
||||||
|
*/
|
||||||
|
|
||||||
class Solution {
|
class Solution {
|
||||||
public:
|
public:
|
||||||
static int dominantIndex(const std::vector<int>& nums) {
|
static int dominantIndex(const std::vector<int>& nums) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,13 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 452. Minimum Number of Arrows to Burst Balloons
|
||||||
|
* There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [xstart, xend] denotes a balloon whose horizontal diameter stretches between xstart and xend. You do not know the exact y-coordinates of the balloons.
|
||||||
|
* Arrows can be shot up directly vertically (in the positive y-direction) from different points along the x-axis. A balloon with xstart and xend is burst by an arrow shot at x if xstart <= x <= xend. There is no limit to the number of arrows that can be shot. A shot arrow keeps traveling up infinitely, bursting any balloons in its path.
|
||||||
|
* Given the array points, return the minimum number of arrows that must be shot to burst all balloons.
|
||||||
|
*/
|
||||||
|
|
||||||
class Solution {
|
class Solution {
|
||||||
public:
|
public:
|
||||||
static int findMinArrowShots(std::vector<std::vector<int>>& points) {
|
static int findMinArrowShots(std::vector<std::vector<int>>& points) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,13 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 373. Find K Pairs with Smallest Sums
|
||||||
|
* You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.
|
||||||
|
* Define a pair (u, v) which consists of one element from the first array and one element from the second array.
|
||||||
|
* Return the k pairs (u1, v1), (u2, v2), ..., (uk, vk) with the smallest sums.
|
||||||
|
*/
|
||||||
|
|
||||||
class Solution {
|
class Solution {
|
||||||
private:
|
private:
|
||||||
static auto getCartesianProduct(const std::vector<int>& p, const std::vector<int>& q, int limP, int limQ) {
|
static auto getCartesianProduct(const std::vector<int>& p, const std::vector<int>& q, int limP, int limQ) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,21 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 8. String to Integer
|
||||||
|
* Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function).
|
||||||
|
* The algorithm for myAtoi(string s) is as follows:
|
||||||
|
* Read in and ignore any leading whitespace.
|
||||||
|
* Check if the next character (if not already at the end of the string) is '-' or '+'. Read this character in if it is either. This determines if the final result is negative or positive respectively. Assume the result is positive if neither is present.
|
||||||
|
* Read in next the characters until the next non-digit character or the end of the input is reached. The rest of the string is ignored.
|
||||||
|
* Convert these digits into an integer (i.e. "123" -> 123, "0032" -> 32). If no digits were read, then the integer is 0. Change the sign as necessary (from step 2).
|
||||||
|
* If the integer is out of the 32-bit signed integer range [-231, 231 - 1], then clamp the integer so that it remains in the range. Specifically, integers less than -231 should be clamped to -231, and integers greater than 231 - 1 should be clamped to 231 - 1.
|
||||||
|
* Return the integer as the final result.
|
||||||
|
* Note:
|
||||||
|
* Only the space character ' ' is considered a whitespace character.
|
||||||
|
* Do not ignore any characters other than the leading whitespace or the rest of the string after the digits.
|
||||||
|
*/
|
||||||
|
|
||||||
class Solution {
|
class Solution {
|
||||||
public:
|
public:
|
||||||
static int myAtoi(const std::string& s) {
|
static int myAtoi(const std::string& s) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue