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> plusOne(vector<int> &digits) { | |
int t = digits.size(); | |
reverse(digits.begin(), digits.end()); | |
int q = 0; | |
int sum = 0; | |
sum = digits[0] + 1;//第一位加1 | |
q = sum/10;//取得进位 | |
sum %= 10;//取余数。 |
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: | |
int removeDuplicates(int A[], int n) { | |
if(n <= 1) return n;//如果是空的或者只有一个元素,直接返回就行。 | |
int length = 1;//初始化总长度为1; | |
int cnt = 1,i,j;//单个元素计数,初始化为1; | |
for(i = 1,j = 1; j < n; j++){//从第二个元素开始比较;i作为指示某元素应该放的位置,j作为遍历到的元素的位置; | |
if(A[j] == A[j-1]){//如果和前一个元素相同。用j指示。 | |
if(cnt >= 2) continue;//如果单个元素个数已经大于或者等于2,则跳过。 |
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 <iostream> | |
#include <cstring> | |
#include <fstream> | |
using namespace std; | |
int state[3];//每个瓶子的状态。 | |
int vol[3];//每个瓶子里的水量 | |
bool vis[200][200][200]; | |
bool flag; |
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
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
#include <iostream> | |
#include <cstring> | |
#include <fstream> | |
#define N 4 | |
using namespace std; | |
int board[N][N]; | |
int total; | |
int maxm; |
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 <iostream> | |
#include <cstring> | |
#include <fstream> | |
#include <algorithm> | |
#include <vector> | |
#include <cstdlib> | |
#include <iomanip> | |
#include <cmath> | |
#define N 10 |
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
代码1:1.128秒 | |
#include <iostream> | |
#include <string.h> | |
#include <fstream> | |
#include <algorithm> | |
using namespace std; | |
int m[100],query; | |
int main(){ | |
//ifstream fin; |
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 <iostream> | |
#include <string.h> | |
#include <fstream> | |
#include <algorithm> | |
using namespace std; | |
int poker[10],suit[10]; | |
char temppoker[10],tempsuit[10]; | |
void print_result(int &res){ | |
cout<<"Hand: "; |
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 <iostream> | |
#include <vector> | |
#include <string.h> | |
#include <fstream> | |
using namespace std; | |
void dfs(int *sy,vector<vector<int> > matrix,int n,int p,int cur,int &r){ | |
if(cur == p){//如果枚举到了i个。 | |
int res[n][p]; | |
memset(res, 0, sizeof(res)); |
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 <iostream> | |
#include <vector> | |
using namespace std; | |
int main(){ | |
int n; | |
while(scanf("%d",&n)){ | |
if(n == 0)break; | |
int pos, neg, x, y, tag; | |
vector<int> veca,vecb; |