# Climbing Stairs LeetCode Solution

Here, We see Climbing Stairs problem Solution. This Leetcode problem is done in many programming languages like C++, Java, JavaScript, Python, etc., with different approaches.

## Problem Statement ->

You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

```Example 1:
Input: n = 2
Output: 2
Explanation: There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps

Example 2:
Input: n = 3
Output: 3
Explanation: There are three ways to climb to the top.
1. 1 step + 1 step + 1 step
2. 1 step + 2 steps
3. 2 steps + 1 step```

## Climbing Stairs Leetcode Solution C++ ->

```.wp-block-code {
border: 0;
}

.wp-block-code > div {
overflow: auto;
}

.shcb-language {
border: 0;
clip: rect(1px, 1px, 1px, 1px);
-webkit-clip-path: inset(50%);
clip-path: inset(50%);
height: 1px;
margin: -1px;
overflow: hidden;
position: absolute;
width: 1px;
word-wrap: normal;
word-break: normal;
}

.hljs {
box-sizing: border-box;
}

.hljs.shcb-code-table {
display: table;
width: 100%;
}

.hljs.shcb-code-table > .shcb-loc {
color: inherit;
display: table-row;
width: 100%;
}

.hljs.shcb-code-table .shcb-loc > span {
display: table-cell;
}

.wp-block-code code.hljs:not(.shcb-wrap-lines) {
white-space: pre;
}

.wp-block-code code.hljs.shcb-wrap-lines {
white-space: pre-wrap;
}

.hljs.shcb-line-numbers {
border-spacing: 0;
counter-reset: line;
}

.hljs.shcb-line-numbers > .shcb-loc {
counter-increment: line;
}

.hljs.shcb-line-numbers .shcb-loc > span {
}

.hljs.shcb-line-numbers .shcb-loc::before {
border-right: 1px solid #ddd;
content: counter(line);
display: table-cell;
text-align: right;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
white-space: nowrap;
width: 1%;
}
```class Solution {
public:
int dp;
int climbStairs(int n) {
if(dp[n]!=0) return dp[n];

if(n==1 || n==2) return n;
dp[n]=climbStairs(n-1)+climbStairs(n-2);
return dp[n];
}
};
```Code language: C++ (cpp)```

## Climbing Stairs Leetcode Solution Java ->

``````class Solution {
public int climbStairs(int n) {
if(n == 0 || n == 1 || n == 2){return n;}
int[] mem = new int[n];
mem = 1;
mem = 2;
for(int i = 2; i < n; i++){
mem[i] = mem[i-1] + mem[i-2];
}
return mem[n-1];
}
}
```Code language: Java (java)```

## Climbing Stairs Leetcode Solution JavaScript ->

``````var climbStairs = function(n) {
let prev = 0;
let curr = 1;
let tmp;
for(let i = 1; i <= n; i++){
tmp = prev;
prev = curr;
curr += tmp;
}
return curr;
};
```Code language: JavaScript (javascript)```

## Climbing Stairs Leetcode Solution Python ->

``````class Solution(object):
def climbStairs(self, n):
a, b = 1, 1
for i in range(n):
a, b = b, a + b
return a
```Code language: Python (python)```

#### Zigzag Conversion LeetCode Solution

The string PAYPALISHIRING is written in a zigzag pattern on a given number of rows…

#### Median of Two Sorted Arrays LeetCode Solution

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time…

#### Rotate Image LeetCode Solution

You are given an n x n 2D matrix representing an image, rotate the image…

#### Delete Node in a Linked List LeetCode Solution

There is a singly-linked list head and we want to delete a node node in…

#### Reverse Linked List LeetCode Solution

Given the head of a singly linked list, reverse the list, and return the reversed list.