楼主: 304671127
跳转到指定楼层
上一主题 下一主题
收起左侧

snapchat电面gg

🔗
何打发123 2016-9-13 09:37:30 | 只看该作者
全局:
alucardzhou 发表于 2016-9-13 09:18
int[][] matrix2 =
            {{0,1,1,1,1,0},
             {1,1,0,0,1,0},

你自己再跑一下。。。 结果明明就是-1.。。。
回复

使用道具 举报

🔗
alucardzhou 2016-9-13 11:08:43 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
何打发123 2016-9-13 11:52:37 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
alucardzhou 2016-9-13 12:05:12 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
何打发123 2016-9-13 12:18:17 | 只看该作者
全局:

小伙伴你看看私信呀~ 我给你留言啦!
回复

使用道具 举报

全局:
把最边上的加入队列进行bfs啊。最终到得了的就返回步数,不行的返回-1
回复

使用道具 举报

🔗
白丁117 2016-9-14 08:16:41 | 只看该作者
全局:
so讨论结果是bfs 4个方向?
回复

使用道具 举报

🔗
dukangs 2016-9-21 03:22:05 | 只看该作者
全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

🔗
wanghwadad 2016-9-24 04:32:43 | 只看该作者
全局:
  1. //BFS loop through all the positions in two dimensional array
  2. //BFS solve this problem
  3. public int solve(int[][] input){
  4.      if(input == null || input.length == 0 || input[0].length == 0){
  5.          return 0;
  6.     }
  7.      int rowLength =input.length;
  8.      int colLength = input[0].length;
  9.      Queue<Position> queue = new LinkedList<Position>();
  10.      for(int i = 0; i < rowLength; i++){
  11.          if(input[i][0] == 0){
  12.              queue.add(new Position(i, 0, 0));
  13.           }
  14.      }
  15.      boolean[][]visited = new boolean[rowLenght][colLength];
  16.      int[][]neighbors = {{0,1}, {0, -1}, {-1, 0}, {1, 0}};
  17.      while(!queue.isEmpty()){
  18.          Position position = queue.poll();
  19.          int y = position.y;
  20.          int x = position.x;
  21.          int step = position.step;
  22.          if(y == (colLength - 1))
  23.              return step;
  24.          for(int i = 0; i < 4; i++){
  25.             int row = x + neighbors[i][0];
  26.             int col = y + neighbors[i][1];
  27.             if(row >= 0 && row < rowLength && col >= 0 && col < colLength && input[row][col] == 0 && !visited[row][col]){
  28.                    queue.add(new Position(row, col, step + 1));
  29.                    visited[row][col] = true;
  30.               }
  31.          }
  32.          return -1;
  33.      }
  34. }
  35. private class Position{
  36.      int x;
  37.      int y;
  38.      int step;
  39.      Position(int x, int y, int step){
  40.        this. x = x;
  41.        this. y = y;
  42.        this.step = step;
  43.     }
  44. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表