由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问个Google面题
相关主题
求教一道经典面题的解法贡献某公司onsite面经
攒人品,google电话面经about DFS
A家电面题现在出发去F onsite
Depth-first search是否属于动态规划?被问到一个题目
[面试题] 如何打印一个二叉树level by level?面试题总结(2) - Two/Three pointers
rejected by facebook after 2nd phone interview这个题目有什么trick
Bloomberg on-campus interview (failed) 求教G家,A家,E 家, H家, E家面筋,赞人品喽~
问个计算化学问题:怎么读GRID?leetcode word search
相关话题的讨论汇总
话题: white话题: cell话题: grids话题: black话题: queue
进入JobHunting版参与讨论
1 (共1页)
D****6
发帖数: 278
1
之前在版上看到的。
Given a matrix which contains black and white grids, use a method to find
out if the white grids are connected or not, if yes, return true.
这题是不是就是类似garbage collection mark and sweep. DFS就行了吧。 还有什么
高级做法吗?
L***Q
发帖数: 508
2
如果可以改动matrix的值,有一个简单办法。
Idea: 如果所有white的cell相连,那么从任何一个white cell开始,往四个方向扩展
,把遇到的white都改成black,那么最终所有cell都是black。
step 1:find any white cell as start point;
step 2: use a queue or stack to record white cells: get a cell, set it as
black, and then check the four directions. If a neighbor is white, put it in
queue/stack; Finish when queue/stack is empty
step 3: check the board again, return false if finding a white cell.
Complexity O(n^2). 如果两个white cell (i, j)和(i+1, j+1)算是相连,那step 2就
是check 8个方向

【在 D****6 的大作中提到】
: 之前在版上看到的。
: Given a matrix which contains black and white grids, use a method to find
: out if the white grids are connected or not, if yes, return true.
: 这题是不是就是类似garbage collection mark and sweep. DFS就行了吧。 还有什么
: 高级做法吗?

c**e
发帖数: 298
3
都连的条件是最多只有两个白点,它们的周围只有一个白点。遍历所有节点,每次检查
4个相连的点。
不知有没有更好的。

【在 D****6 的大作中提到】
: 之前在版上看到的。
: Given a matrix which contains black and white grids, use a method to find
: out if the white grids are connected or not, if yes, return true.
: 这题是不是就是类似garbage collection mark and sweep. DFS就行了吧。 还有什么
: 高级做法吗?

D****6
发帖数: 278
4
想了想这题怎么都要走一遍。mark and sweep最容易了。
c******a
发帖数: 789
5
不改原board也可以啊。
1. 从任一个白点开始,用你的queue走,走到走不动,看看总共搞过几个白点
2. check board,看一共有几个白点
看看1和2的白点数是不是一样。

in

【在 L***Q 的大作中提到】
: 如果可以改动matrix的值,有一个简单办法。
: Idea: 如果所有white的cell相连,那么从任何一个white cell开始,往四个方向扩展
: ,把遇到的white都改成black,那么最终所有cell都是black。
: step 1:find any white cell as start point;
: step 2: use a queue or stack to record white cells: get a cell, set it as
: black, and then check the four directions. If a neighbor is white, put it in
: queue/stack; Finish when queue/stack is empty
: step 3: check the board again, return false if finding a white cell.
: Complexity O(n^2). 如果两个white cell (i, j)和(i+1, j+1)算是相连,那step 2就
: 是check 8个方向

1 (共1页)
进入JobHunting版参与讨论
相关主题
leetcode word search[面试题] 如何打印一个二叉树level by level?
DFS比BFS好在哪?rejected by facebook after 2nd phone interview
请问两个meeting schedule的题Bloomberg on-campus interview (failed) 求教
leetcode做伤心了问个计算化学问题:怎么读GRID?
求教一道经典面题的解法贡献某公司onsite面经
攒人品,google电话面经about DFS
A家电面题现在出发去F onsite
Depth-first search是否属于动态规划?被问到一个题目
相关话题的讨论汇总
话题: white话题: cell话题: grids话题: black话题: queue