📣 黑五网一特惠|VIP一年通行证5折,蓝莓、Offer多多同步特惠
回复: 5
跳转到指定楼层
上一主题 下一主题
收起左侧

OCI店面挂经

全局:

2020(7-9月) 工程类 博士 全职@oracle - 内推 - 技术电面  | | Fail | 其他

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

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

x
今天店面,是infra data组
上来聊经历,半个小时。然后做一题,题目是
一个file里有重复单词,要求写两个函
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
fs recursion。楼主刷题少在LC没有见过原题。



评分

参与人数 4大米 +5 收起 理由
lynx622 + 2 给你点个赞!
MilkyKMKY + 1 给你点个赞!
MayPapa + 1 给你点个赞!
一剑终情 + 1 赞一个

查看全部评分


上一篇:OCI西雅图电面
下一篇:Akuna web coding+core OA 疑惑之拒
🔗
wsx247 2020-8-31 03:29:17 | 只看该作者
全局:
方便細說一下dfs recursion怎麼用嗎
回复

使用道具 举报

🔗
landy622 2020-8-31 15:34:44 | 只看该作者
全局:
本帖最后由 landy622 于 2020-8-31 15:36 编辑

DFS的话也许是用Trie Tree?如果段落只有后几个词不同的话,这个方法还可以

求指正 求加米

  1. public class CompressFile {
  2.     @Test
  3.     public void test0() {
  4.         String[] lines = {"123 456 789", "987 654 321"};
  5.         Util util = new Util();
  6.         util.compress(lines);
  7.         assertArrayEquals(lines, util.depress());
  8.     }
  9.     @Test
  10.     public void test1() {
  11.         String[] lines = {"123 456 789", "123 456"};
  12.         Util util = new Util();
  13.         util.compress(lines);
  14.         assertArrayEquals(lines, util.depress());
  15.     }

  16.     private class Util {
  17.         int size = 0;
  18.         Trie trie = new Trie();

  19.         public String[] depress() {
  20.             String[] res = new String[size];
  21.             for (int i = 0; i < size; ++i) {
  22.                 res = trie.get(i);
  23.             }
  24.             return res;
  25.         }

  26.         public void compress(String[] lines) {
  27.             size = lines.length;
  28.             for (int i = 0; i < lines.length; ++i) {
  29.                 trie.insert(i, lines);
  30.             }
  31.         }
  32.     }

  33.     private class TrieNode {
  34.         // line # - next word's node
  35.         Map<Integer, TrieNode> map = new HashMap<>();
  36.         String word;

  37.         TrieNode(String word) {
  38.             this.word = word;
  39.         }
  40.     }

  41.     private class Trie {
  42.         TrieNode root = new TrieNode(null);

  43.         void insert(int index, String[] lines) {
  44.             String line = lines[index];
  45.             String[] words = line.split(" ");
  46.             TrieNode curr = root;
  47.             TrieNode next = null;
  48.             for (String word : words) {
  49.                 // get next word in this line
  50.                 next = curr.map.getOrDefault(index, new TrieNode(word));
  51.                 curr.map.put(index, next);
  52.                 curr = next;
  53.             }
  54.         }

  55.         String get(int index) {
  56.             List<String> list = new ArrayList<>();
  57.             TrieNode node = root;
  58.             while (node.map.containsKey(index)) {
  59.                 TrieNode next = node.map.get(index);
  60.                 list.add(next.word);
  61.                 node = next;
  62.             }
  63.             return String.join(" ", list);
  64.         }
  65.     }
  66. }
复制代码


回复

使用道具 举报

🔗
landy622 2020-9-1 00:52:45 | 只看该作者
全局:
landy622 发表于 2020-8-31 15:34
DFS的话也许是用Trie Tree?如果段落只有后几个词不同的话,这个方法还可以

求指正 求加米

请忽略上文 似乎不太对我再想想
回复

使用道具 举报

🔗
Black Liu 2020-9-16 05:03:35 | 只看该作者
全局:
这个是不是压缩的时候可以用Trie然后在每个单词结尾的时候记录它的index。index就是二维的。行数和具体的空格切割的index
然后解压缩的时候可以直接通过trie decode?
回复

使用道具 举报

🔗
 楼主| 草莓alice 2020-9-16 06:30:52 | 只看该作者
全局:
Black Liu 发表于 2020-9-15 13:03
这个是不是压缩的时候可以用Trie然后在每个单词结尾的时候记录它的index。index就是二维的。行数和具体的空 ...

思路是对的
回复

使用道具 举报

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

本版积分规则

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