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

10分钟前结束的facebook二面

🔗
primbo 2016-3-9 03:46:26 | 只看该作者
全局:
snakefly 发表于 2016-3-9 03:37
就一道decode,原题。。。。。。。。。。
有前辈decode 加另一道题  双双bug free 都挂了,我也是只能战 ...

那可能是因为一面面的不好?
回复

使用道具 举报

🔗
snakefly 2016-3-9 04:41:50 | 只看该作者
全局:
primbo 发表于 2016-3-9 03:46
那可能是因为一面面的不好?

感觉很奇怪  一面不好怎么拿到2面的呢
回复

使用道具 举报

🔗
primbo 2016-3-9 05:06:17 | 只看该作者
全局:
DJ963 发表于 2016-3-9 03:32
嗯 必须的啊~! 你现在有消息了吗

楼主做过 target sum in 2D array and 3D matrix么? 2D的用划窗搞定,3D的呢?
回复

使用道具 举报

🔗
 楼主| DJ963 2016-3-9 05:07:43 | 只看该作者
全局:
primbo 发表于 2016-3-9 05:06
楼主做过 target sum in 2D array and 3D matrix么? 2D的用划窗搞定,3D的呢?

2D做过~ 3D没有啊~ 3D是三维的坐标吗
回复

使用道具 举报

🔗
primbo 2016-3-9 05:09:49 | 只看该作者
全局:
DJ963 发表于 2016-3-9 05:07
2D做过~ 3D没有啊~ 3D是三维的坐标吗

2D是 array,3D是matrix。我也是看面经里面提到的。
回复

使用道具 举报

🔗
 楼主| DJ963 2016-3-9 05:11:55 | 只看该作者
全局:
primbo 发表于 2016-3-9 05:09
2D是 array,3D是matrix。我也是看面经里面提到的。

//find the sum of a rectangle in the 2D matrix equals to target
public class Find_Target_Value_In_2D_Matrix_Rectangle {
        int[][] sum;
        public Find_Target_Value_In_2D_Matrix_Rectangle(int[][] input){
                if(input == null || input.length == 0 || input[0].length == 0){
                        return;
                }
                sum = new int[input.length+1][input[0].length+1];
                for(int i = 0; i < input.length; i++){
                        for(int j = 0; j < input[0].length; j++){
                                sum[i+1][j+1] = input[i][j] + sum[i][j+1] + sum[i+1][j] - sum[i][j];
                        }
                }
        }
        public boolean findTarget(int target){
                return solution(0,0,0,0,target);
        }
        public int findValue(int row1, int col1, int row2, int col2){
                int smallRow = Math.min(row1, row2);
                int maxRow = Math.max(row1, row2);
                int smallCol = Math.min(col1, col2);
                int maxCol = Math.max(col1, col2);
               
                if(++maxRow > sum.length){
                        maxRow = sum.length;
                }
                if(++maxCol > sum[0].length){
                        maxCol = sum[0].length;
                }
                return sum[maxRow][maxCol] - sum[maxRow][smallCol] - sum[smallRow][maxCol] + sum[smallRow][smallCol];
        }
       
        public boolean solution(int row1, int col1, int row2, int col2, int target){
                if(row1 > row2 || col1 > col2){
                        return false;
                }
                int curr = findValue(row1, col1, row2, col2);
                if(curr == target){
                        return true;
                }
                if(curr > target){
                        return solution(row1+1, col1, row2, col2, target) || solution(row1, col1+1, row2, col2, target);
                }else{
                        return solution(row1, col1, row2+1, col2, target) || solution(row1, col1, row2, col2+1, target);
                }
        }
}

评分

参与人数 2大米 +13 收起 理由
primbo + 3 感谢分享!
xiaozhuxiaozhu + 10 感谢分享!

查看全部评分

回复

使用道具 举报

全局:
DJ963 发表于 2016-3-9 05:11
//find the sum of a rectangle in the 2D matrix equals to target
public class Find_Target_Value_In ...

http://www.1point3acres.com/bbs/thread-174600-1-1.html
这个妹子的2面么?

回复

使用道具 举报

全局:
DJ963 发表于 2016-3-9 05:11
//find the sum of a rectangle in the 2D matrix equals to target
public class Find_Target_Value_In ...

你这代码是2问么?
回复

使用道具 举报

🔗
 楼主| DJ963 2016-3-9 07:46:46 | 只看该作者
全局:
xiaozhuxiaozhu 发表于 2016-3-9 07:44
你这代码是2问么?

差不多吧~ 随便写的
回复

使用道具 举报

全局:
DJ963 发表于 2016-3-9 07:46
差不多吧~ 随便写的

Find_Target_Value_In_2D_Matrix_Rectangle和find target的关系是什么
回复

使用道具 举报

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

本版积分规则

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