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

脸书店面

全局:

2017(1-3月) 码农类General 硕士 全职@meta - 内推 - 技术电面  | | Other | 应届毕业生

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x


发面经 攒人品

只问了一道题,word l
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
了一道题,是不是就没戏了。。。

评分

参与人数 1大米 +3 收起 理由
Mr.Sagemaker + 3 感谢分享!

查看全部评分


上一篇:google Feb 2 电面
下一篇:google intern电面面经

本帖被以下淘专辑推荐:

全局:
我以前面过也是一道题,不会的,听上去你写的不错,应该没问题,可能他觉得已经够了把,希望一切顺利!
回复

使用道具 举报

🔗
lhh_NJU 2017-2-20 07:08:06 | 只看该作者
全局:
是所有可能路径, 那就用DFS最方便了.  要是输出所有最短路径还挺麻烦的..
回复

使用道具 举报

🔗
bigbearlake 2017-3-1 15:08:02 | 只看该作者
全局:
  1. public class WordLadderIII {

  2.     public static void main(String[] args) {
  3.         WordLadderIII w = new WordLadderIII();
  4.         Set<String> dict = new HashSet<>();
  5.         dict.add("hot");
  6.         dict.add("dot");
  7.         dict.add("dog");
  8.         dict.add("lot");
  9.         dict.add("log");
  10.         dict.add("cog");
  11.         List<List<String>> res = w.getAllLadders("hit", "cog", dict);
  12.         for (List<String> list : res) {
  13.             for (String s : list) {
  14.                 System.out.print(s + "->");
  15.             }
  16.             System.out.println();
  17.         }
  18.     }

  19.     public List<List<String>> getAllLadders(String start, String end, Set<String> dict) {
  20.         List<List<String>> res = new ArrayList<>();
  21.         if (dict == null || dict.size() == 0) {
  22.             return res;
  23.         }
  24.         dict.remove(start);
  25.         List<String> list = new ArrayList<>();
  26.         list.add(start);
  27.         helper(res, start, end, dict, list);
  28.         return res;
  29.     }

  30.     public void helper(List<List<String>>  res, String start, String end, Set<String> set, List<String> list) {
  31.         if (start.equals(end)) {
  32.             res.add(new ArrayList<>(list));
  33.             return;
  34.         }

  35.         for (int i = 0; i < start.length(); i++) {
  36.             StringBuilder sb = new StringBuilder(start);
  37.             for (char c = 'a'; c <= 'z'; c++) {
  38.                 sb.setCharAt(i, c);
  39.                 String newStr = sb.toString();
  40.                 if (set.contains(newStr)) {
  41.                     set.remove(newStr);
  42.                     list.add(newStr);
  43.                     helper(res, newStr, end, set, list);
  44.                     list.remove(list.size() - 1);
  45.                     set.add(newStr);
  46.                 }
  47.             }
  48.         }
  49.     }
  50. }
复制代码
回复

使用道具 举报

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

本版积分规则

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