This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <arpa/inet.h> | |
#include <sys/socket.h> | |
#include <linux/socket.h> | |
#define ETH_P_WSMP 0x88DC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//复杂度比较高的写法 | |
//原创+参考 | |
class Solution { | |
public: | |
vector<vector<int>> generate(int numRows) { | |
vector<vector<int>> array(numRows); | |
for(int i = 0;i < numRows;++i){ //第几行 | |
array[i].resize(i+1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; | |
*/ | |
class Solution { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; | |
*/ | |
class Solution { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
vector<int> findDisappearedNumbers(vector<int>& nums) { | |
vector<int> array; | |
vector<int> hash; | |
hash.resize(nums.size()+1); | |
for(int i = 0;i < nums.size();++i) | |
hash[nums[i]]++; | |
for(int i = 1;i <= nums.size();++i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//测试性能:Runtime: 12 ms, faster than 26.44% | |
class Solution { | |
public: | |
int minCostClimbingStairs(vector<int>& cost) { | |
int n=(int)cost.size(); | |
vector<int> dp(n); | |
dp[0]=cost[0]; | |
dp[1]=cost[1]; | |
for (int i=2; i<n; ++i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//真的是很新奇的方法,使用位运算来进行求解 | |
//Runtime: 24 ms, faster than 30.40% | |
class Solution { | |
public: | |
int majorityElement(vector<int>& nums) { | |
int major = 0,n = nums.size(); | |
for(int i = 0,mask = 1;i < 32;i++,mask <<= 1){ | |
int bitCounts = 0; | |
for(int j = 0;j < n;j++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//效率不算高 | |
//Runtime: 8 ms, faster than 55.20% | |
/** | |
* Definition for a binary tree node. | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//使用Fibonacci sequence方法实现 | |
//效率总体来说还是挺高的 | |
//Runtime: 0 ms, faster than 100.00% | |
class Solution { | |
public: | |
int climbStairs(int n) { | |
int Fib[n] = {0}; | |
Fib[0] = Fib[1] = 1; | |
// if(n <= 2) | |
// return n; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Runtime: 16 ms, faster than 99.48% | |
class MinStack { | |
public: | |
/** initialize your data structure here. */ | |
stack<pair<int,int>> st; | |
MinStack() { | |
} |