-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution_climbStairs.java
51 lines (45 loc) · 1003 Bytes
/
Solution_climbStairs.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.bupt.kcrosswind.Leetcode;
public class Solution_climbStairs {
public static int climbStairs(int n) {
if (n == 1) {
return 1;
} else if (n == 2) {
return 2;
}
int[] reslut = new int[n];
reslut[0] = 1;
reslut[1] = 2;
for (int i = 2; i < n; i++) {
reslut[i] = reslut[i - 1] + reslut[i - 2];
}
return reslut[n - 1];
}
public static int climbStairs2(int n) {
if (n == 0) {
return 0;
} else if (n == 1) {
return 0;
} else {
return 2 + climbStairs2(n - 1) + climbStairs2(n - 2);
}
}
public static void main(String[] args) {
// System.out.println(climbStairs(44));
String s = "asdf";
char[] c = s.toCharArray();// ×Ö·û´®ÊÇÓÐÕâ¸ö¹¦ÄܵÄ
for (int i = 0; i < c.length; i++) {
System.out.println(c[i]);
}
int[] A = {};
int[] B = { 1 };
if (A.length == 0) {
A = B;
for (int i = 0; i < B.length; i++) {
System.out.println(A[i]);
}
System.out.println("A==null");
} else {
System.out.println("A!=null");
}
}
}