Skip to content

Commit 6563326

Browse files
authored
Create Main.java
1 parent 0df5b0a commit 6563326

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// "static void main" must be defined in a public class.
2+
public class Main {
3+
4+
public final static Map<Map.Entry<Integer,Integer>,Integer> map = new HashMap();
5+
public static void main(String[] args) {
6+
System.out.println(gridTraveler(1,1));
7+
System.out.println(gridTraveler(3,1));
8+
System.out.println(gridTraveler(3,3));
9+
System.out.println(gridTraveler(2,2));
10+
System.out.println(gridTraveler(5,5));
11+
12+
}
13+
14+
public static int gridTraveler(int x,int y){
15+
if(x == 0 || y == 0){
16+
return 0;
17+
}
18+
19+
if(x == 1 && y == 1){
20+
return 1;
21+
}
22+
23+
if(map.containsKey(Map.entry(x,y))){
24+
return map.get(Map.entry(x,y));
25+
}
26+
27+
int ans = gridTraveler(x-1,y)+gridTraveler(x,y-1);
28+
map.put(Map.entry(x,y),ans);
29+
return ans;
30+
}
31+
}

0 commit comments

Comments
 (0)