Skip to content

Commit 769edb9

Browse files
committed
jump game
1 parent a99b00d commit 769edb9

File tree

5 files changed

+74
-3
lines changed

5 files changed

+74
-3
lines changed

385.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Program: Mini Parser
44
Description:
55
66
Date: 2016-08-17 14:21:22
7-
Last modified: 2016-08-17 14:22:10
7+
Last modified: 2016-08-17 14:27:22
88
GCC version: 4.9.3
99
*****************************************/
1010

41.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//coding:utf-8
2+
/*****************************************
3+
Program: First missing positive
4+
Description:
5+
6+
Date: 2016-08-17 14:54:37
7+
Last modified: 2016-08-17 15:02:25
8+
GCC version: 4.9.3
9+
*****************************************/
10+
11+
//put every integer into corresponding position
12+
//1 into A[1], 5 into A[5], etc
13+
14+
#include <vector>
15+
16+
class Solution {
17+
public:
18+
int firstMissingPositive(vector<int>& A) {
19+
const int n = A.size();
20+
for(int i = 0; i < n; ++ i)
21+
while(A[i] > 0 && A[i] <= n && A[A[i] - 1] != A[i])
22+
swap(A[i], A[A[i] - 1]);
23+
24+
for(int i = 0; i < n; ++ i)
25+
if(A[i] != i + 1)
26+
return i + 1;
27+
28+
return n + 1;
29+
}
30+
};

55.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//coding:utf-8
2+
/*****************************************
3+
Program: Jump Game
4+
Description:
5+
6+
Date: 2016-08-17 15:19:33
7+
Last modified: 2016-08-17 15:19:54
8+
GCC version: 4.9.3
9+
*****************************************/
10+
11+
#include <vector>
12+
13+
class Solution {
14+
bool helper(vector<int>& nums, int e){
15+
if(e == 0)
16+
return true;
17+
if(nums[e - 1] >= 1)
18+
return helper(nums, e - 1);
19+
else{
20+
if(e - 1 == 0)
21+
return false;
22+
for(int i = e - 2; i >= 0; i--){
23+
if(nums[i] >= e - i){
24+
if(i >= 1)
25+
return helper(nums, i);
26+
else
27+
return true;
28+
}
29+
}
30+
return false;
31+
}
32+
}
33+
public:
34+
bool canJump(vector<int>& nums) {
35+
return helper(nums, nums.size() - 1);
36+
}
37+
};

6.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ Program: zigzag
44
Description:
55
Shanbo Cheng: [email protected]
66
Date: 2016-07-19 08:25:26
7-
Last modified: 2016-07-19 08:25:39
7+
Last modified: 2016-08-17 14:33:24
88
GCC version: 4.7.3
99
*/
1010

11+
#include <string>
12+
1113
class Solution {
1214
public:
1315
string convert(string s, int numRows) {

99.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Description:
55
Shanbo Cheng: [email protected]
66
Date: 2016-08-10 14:03:25
7-
Last modified: 2016-08-11 13:04:08
7+
Last modified: 2016-08-17 10:50:49
88
GCC version: 4.9.3
99
***********************************************************/
1010
/**
@@ -20,6 +20,8 @@ GCC version: 4.9.3
2020
//inorder traverse, the first element is the one bigger than the successor
2121
//second element is the one smaller the previous ones
2222
//
23+
#include "misc.h"
24+
2325
class Solution {
2426
TreeNode* first;
2527
TreeNode* second;

0 commit comments

Comments
 (0)