12
返回列表 发新帖
楼主: 匿名
跳转到指定楼层
上一主题 下一主题
收起左侧

FB新鲜电面

🔗
twocold 2020-5-24 07:01:02 | 只看该作者
全局:
1st one
  1. public int minMeetingRooms(int[][] intervals) {
  2.         Arrays.sort(intervals, (a,b) -> a[0] - b[0]);
  3.         PriorityQueue<int[]> pq = new PriorityQueue<>((a,b) -> (a[1] - b[1]));
  4.                                                       
  5.         for(int[] in: intervals) {
  6.             pq.add(in);
  7.             for(int i: in) {
  8.                 System.out.print(i + " ");
  9.             }
  10.              System.out.println();
  11.              if(!pq.isEmpty() && pq.peek()[1] <= in[0]) {
  12.                 pq.poll();
  13.             }
  14.         }
  15.         return pq.size();
  16.     }
复制代码
回复

使用道具 举报

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

使用道具 举报

🔗
403Forbidden 2020-5-24 23:49:00 | 只看该作者
全局:
第二题用BFS就足够了。O(m*n)可解。
回复

使用道具 举报

🔗
ericbado 2020-5-25 07:03:15 | 只看该作者
全局:
第二题难道不是直接逐行扫描就行了吗?从0到m-1行,从0到n-1列,每个元素和右边以及下面的元素比较,如果不一样,a加入b的列表,b加入a的列表,最后返回列表最长的元素
回复

使用道具 举报

🔗
twocold 2020-5-26 09:59:59 | 只看该作者
全局:
tinlittle 发表于 2020-5-23 13:51
珥舞伞是超高频题,应该已经熟读背诵,5分钟实现。这第二道也是极简单的题,UF是不合适的,Python五分钟,J ...

能是否写下做法
如果可以的话,可以写一个java的solution吗
回复

使用道具 举报

🔗
twocold 2020-5-26 10:12:21 | 只看该作者
全局:
singku 发表于 2020-5-24 01:52
用bfs也可以呀,bfs到不同的就记录邻国

能写下吗?谢谢
回复

使用道具 举报

🔗
csgogogo 2020-5-26 10:41:19 | 只看该作者
全局:
请问楼主是 啥时候毕业的? 还有时间线  谢谢啦
回复

使用道具 举报

🔗
twocold 2020-5-26 11:10:18 | 只看该作者
全局:
第二题 我用的是island的方法,DFS
应该是很烂。希望能用。
  1. class Country {
  2.         int countA = 0;
  3.     int countB = 0;
  4.     public int numIslands(char[][] grid) {
  5.         if(grid == null || grid.length == 0) {
  6.             return 0;
  7.         }
  8.         int row = grid.length;
  9.         int col = grid[0].length;
  10.         for(int i = 0; i < row; i++) {
  11.             for(int j = 0; j < col; j++) {
  12.                 if(grid[i][j] == 'A') {
  13.                     DFSA(grid, i, j);
  14.                 }
  15.                 else {
  16.                     DFSB(grid, i, j);
  17.                 }
  18.             }
  19.         }
  20.         return Math.max(countA, countB);
  21.     }
  22.     private void DFSA(char[][] grid, int row, int col) {
  23.         if(row >= grid.length || row < 0 || col >= grid[0].length || col < 0 ||
  24.           grid[row][col] != 'A'){
  25.             return;
  26.         }
  27.          grid[row][col] = 'a';
  28.          count1++;
  29.          DFSA(grid, row + 1, col);
  30.          DFSA(grid, row - 1, col);
  31.          DFSA(grid, row, col + 1);
  32.          DFSA(grid, row, col - 1);
  33.     }
  34.     private void DFSB(char[][] grid, int row, int col) {
  35.         if(row >= grid.length || row < 0 || col >= grid[0].length || col < 0 ||
  36.           grid[row][col] != 'B'){
  37.             return;
  38.         }
  39.          grid[row][col] = 'b';
  40.          count0++;
  41.          DFSB(grid, row + 1, col);
  42.          DFSB(grid, row - 1, col);
  43.          DFSB(grid, row, col + 1);
  44.          DFSB(grid, row, col - 1);
  45.     }
  46. }
复制代码
回复

使用道具 举报

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

本版积分规则

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