Test
来源:互联网 发布:推荐系统算法模型 编辑:程序博客网 时间:2024/05/16 18:09
package com.company;import java.util.HashMap;import java.util.Map;/** * */public class CountAreaTest { public static void main(String[] args) { int solution = solution(); System.out.println(solution); } public static int solution() { Map<Integer, Map<Integer, Boolean>> map = new HashMap<>(); return helper(0, 0, map); } public static int helper(int x, int y, Map<Integer, Map<Integer, Boolean>> map) { int up = 0, down = 0, left = 0, right = 0; if (map.containsKey(x)) { if (map.get(x).containsKey(y)) { return 0; } else { map.get(x).put(y, true); } } else { Map<Integer, Boolean> temp = new HashMap<>(); temp.put(y, true); map.put(x, temp); } if (move(0,x - 1)) {//0 up = helper(x - 1, y, map); } if (move(1,x + 1)) {//1 down = helper(x + 1, y, map); } if (move(2,y - 1)) {//2 left = helper(x, y - 1, map); } if (move(3,y + 1)) {//3 right = helper(x, y + 1, map); } return up + down + left + right + 1; } //移动的函数 public static boolean move(int i, int direction) { int xLeft = -1, xRight = 4; int yLeft =-3, yRight = 7; boolean isOK = true; switch (i) { case 0: if (direction >= xLeft) { isOK=true; } else { isOK=false; } break; case 1: if (direction < xRight) { isOK=true; } else { isOK=false; } break; case 2: if (direction >= yLeft) { isOK= true; } else { isOK=false; } break; case 3: if (direction < yRight) { isOK=true; } else { isOK= false; } break; } return isOK; }}
阅读全文
0 0
- test
- test
- test
- test
- test
- test
- test
- Test
- test
- Test
- test
- test
- test
- test
- test
- test
- test
- Test
- a标签传值,Java接值乱码
- Capstone训练营第一天
- 2017/12/5 开课第一堂
- 使用postman快速建立MOCK使用篇
- 加载高清大图(本地、在线)---使用subsampling-scale-image-view
- Test
- [HAOI2006]受欢迎的牛
- Windows 源码编译Hadoop 2.7.4生成X64
- Maven生成可以直接运行的jar包的多种方式
- PHP获取二维数组中某一列的值集合
- vfscanf用法解析
- apache 配置
- S32K144 EVB之FTM
- 条款07:对多态基类声明虚析构函数