aboutsummaryrefslogtreecommitdiff
path: root/works/solutions/cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-08-15 14:44:22 +0800
committercrupest <crupest@outlook.com>2020-08-15 14:44:22 +0800
commitf526f35c101484b62e833956ec44791422acd700 (patch)
treef0d9a0eb826288a84491b5619f7987de366ea411 /works/solutions/cpp
parentc47e2d04ce0bbc73ca29ea45f1e8e246fbd340d6 (diff)
downloadcrupest-f526f35c101484b62e833956ec44791422acd700.tar.gz
crupest-f526f35c101484b62e833956ec44791422acd700.tar.bz2
crupest-f526f35c101484b62e833956ec44791422acd700.zip
import(solutions): Add problem 55 .
Diffstat (limited to 'works/solutions/cpp')
-rw-r--r--works/solutions/cpp/55.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/works/solutions/cpp/55.cpp b/works/solutions/cpp/55.cpp
new file mode 100644
index 0000000..d2c2600
--- /dev/null
+++ b/works/solutions/cpp/55.cpp
@@ -0,0 +1,29 @@
+#include <vector>
+
+using std::vector;
+
+#include <algorithm>
+
+class Solution
+{
+public:
+ bool canJump(vector<int> &nums)
+ {
+ int max = 0;
+ const int size = nums.size();
+ for (int i = 0; i < size; i++)
+ {
+ if (i <= max)
+ {
+ max = std::max(max, i + nums[i]);
+ if (max >= size - 1)
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ return false;
+ }
+}; \ No newline at end of file