Adilbenouarrek

class Solution

Feb 3rd, 2020
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. class Solution {
  2. public int climbStairs(int n) {
  3. if (n <= 1) {
  4. return 1;
  5. }
  6. int prev = 1;
  7. int current = 1;
  8. for (int i=2; i<=n; ++i) {
  9. int next = prev + current;
  10. prev = current;
  11. current = next;
  12. }
  13. return current;
  14. }
  15. }
Add Comment
Please, Sign In to add comment