## [LeetCode C++实现]101. Symmetric Tree

/**

* Definition for a binary tree node.

* struct TreeNode {

* int val;

* TreeNode *left;

* TreeNode *right;

* TreeNode() : val(0), left(nullptr), right(nullptr) {}

* TreeNode(int x) : val(x), left(nullptr), righ......

## [LeetCode C++实现]45. 跳跃游戏 II

[LeetCode C++实现]45. 跳跃游戏 II

date:2021-07-12 23:30

url:LeetCode45

class Solution {

public:

int jump(vector<int>& nums) {

int size = nums.size();

int right = 0,step = 0,end = 0;

for(int i = 0;i < size - 1;i++)

{

if(i <= right)

{

right = max(right,i + nums[i]);

if(i == end)

{

end =......

## [LeetCode C++实现]55.跳跃游戏

class Solution {

public:

bool canJump(vector<int>& nums) {

int size = nums.size();

int right = 0;

for(int i = 0;i < size;i++)

{

if(i <= right)

{

right = max(right,i + nums[i]);

if(right >= size - 1)

return true;

}else

return false;

}

return false;

}

};

## [LeetCode C++实现]179. Largest Number

class Solution {

public:

string largestNumber(vector<int>& nums) {

vector<string> strs;

for(auto num:nums)

strs.push_back(to_string(num));

sort(strs.begin(),strs.end(),[](const string& s1,const string& s2){return s1 + s2 > s2 +......

## 程序员面试金典-面试题 08.05. 递归

class Solution {

public:

int multiply(int A, int B) {

if(A == 0 || B == 0)

return 0;

if(A < B)

return B + multiply(A-1,B);

else

return A + multiply(A, B-1);

}

};

clas......

## [LeetCode C++实现]41. First Missing Positive

class Solution {

public:

int firstMissingPositive(vector<int>& nums) {

int n = nums.size();

for(int i = 0;i < n;i++)

{

if(nums[i] <= 0)

nums[i] = n + 1;

}

for (int i = 0; i < n; ++i) {

int num = abs(nums[i]);

if (num <= n) {

nums[num - 1] = -abs(nums[num - 1]);

}

}

for(int i......

## [LeetCode C++实现]165. Compare Version Numbers

class Solution {

public:

int compareVersion(string version1, string version2) {

istringstream v1(version1);

istringstream v2(version2);

while(!v1.eof() || !v2.eof())

{

string s1 = "0",s2 = "0";

if(!v1.eof())

getline(v1,s1,'.');

if(!v2.eof())

getline(v2,s2,'.');

int n1 = atoi(s1.c_str());

int n2 =......

## [LeetCode C++实现]29. Divide Two Integers

class Solution {

public:

int divide(int dividend, int divisor) {

if(dividend == INT_MIN && divisor == -1) return INT_MAX;

long long A = llabs(dividend),B = llabs(divisor),ans = 0;

while(A >= B)

{

long long base = B,m = 1;

while(base << 1 <= A)

{

base <<= 1;

m <<= 1;

......

## [LeetCode C++实现]912. Sort an Array

class Solution {

public:

vector<int> sortArray(vector<int>& nums) {

for(int i = nums.size()-1;i > 0;i--)

{

for(int j = 0;j < i;j++)

if(nums[j] > nums[j+1])

swap(nums[j],nums[j+1]);

}

return nums;

}

};

Time Limit Exceeded

Details

Last executed input

[5864,-1......