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

discovery phone 带超时笨解

全局:

2020(10-12月) 码农类General 硕士 全职@discovery - 猎头 - 技术电面  | | Fail | 在职跳槽

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

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

x
给一个字典和一个字符串, 打印能顺序抽出的词组成的句子, 同一个词 能重复抽,
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
tcode 哪题呢

  1. class Solution {

  2.   public static void main(String[] args) {
  3.     Solution s = new Solution();
  4.     Set<String> d1 = new HashSet<String>();
  5.     d1.addAll(Arrays.asList("i", "live", "love", "ice", "cream", "il", "icream"));
  6.     System.out.print(s.getOutput("iloveicecream", d1));

  7.   }
  8.   public List<List<String>> getOutput(String input,  Set<String> dict) {
  9.     List<List<List<String>>> s = new ArrayList<List<List<String>>>();
  10.     s.add(Arrays.asList(new ArrayList<String>()));
  11.     for(int i = 0; i < input.length(); i ++) {
  12.        List<List<String>> ns = buildUp(input, i, dict, s);
  13.        // System.out.println(ns);
  14.        s.add(ns);
  15.     }
  16.     List<List<String>> result = new ArrayList<List<String>>();
  17.     for (int i =0; i <  s.size();  i++) {
  18.       for (int j = 1; j < s.get(i).size(); j++) {
  19.         result.add(s.get(i).get(j));
  20.       }
  21.     }
  22.     return result;
  23.   }
  24.   // Search for new matching words in the dictionary and apply it to previous solutions
  25.   public List<List<String>> buildUp(String input,
  26.                                      int i,
  27.                                      Set<String> dict,
  28.                                      List<List<List<String>>> solution) {
  29.     List<List<String>> ns = new ArrayList<List<String>>();
  30.     ns.add(new ArrayList<String>());
  31.     for (int j = i; j >=0 ; j--) {
  32.       String prev = input.substring(j, i+1);
  33.       if (dict.contains(prev)) {
  34.          ns.addAll(getNext(prev, solution.get(j)));
  35.       }
  36.     }
  37.     return ns;
  38.   }
  39.   
  40.   public List<List<String>> getNext(String prev,
  41.                                     List<List<String>> solution) {
  42.      List<List<String>> ns = new ArrayList<List<String>>();
  43.      for (List<String> sentence: solution) {
  44.        List<String> clone = new ArrayList<String>(sentence);
  45.        clone.add(prev); //
  46.        ns.add(clone);
  47.      }
  48.      return ns;
  49.   }
  50. }
复制代码

评分

参与人数 2大米 +15 收起 理由
willwillzhang + 3 给你点个赞!
匿名用户-RX1CR + 12

查看全部评分


上一篇:卡夫卡公司电面
下一篇:coupang挂经
推荐
 楼主| agener 2020-12-17 01:34:46 来自APP | 只看该作者
全局:
willwillzhang 发表于 2020-12-13 19:54:59
店面?小紫薯紫薯紫薯
是的 店面 店面
回复

使用道具 举报

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

评分

参与人数 1大米 +1 收起 理由
agener + 1 赞一个

查看全部评分

回复

使用道具 举报

🔗
willwillzhang 2020-12-14 11:54:59 | 只看该作者
全局:
店面?小紫薯紫薯紫薯
回复

使用道具 举报

🔗
 楼主| agener 2020-12-17 01:33:55 来自APP | 只看该作者
全局:
是的,从前向后匹配要容易直观很多。 谢谢回复!  
回复

使用道具 举报

🔗
willwillzhang 2020-12-17 04:09:24 | 只看该作者
全局:

店面的题 感觉好像 先找出 所有的valid words, 然后在取所有的subsets,不知道对不对
回复

使用道具 举报

🔗
 楼主| agener 2020-12-18 12:48:42 来自APP | 只看该作者
全局:
willwillzhang 发表于 2020-12-16 12:09:24
店面的题 感觉好像 先找出 所有的valid words, 然后在取所有的subsets,不知道对不对
要有order 而且重复使用过的字母不能重复使用
回复

使用道具 举报

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

使用道具 举报

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

本版积分规则

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