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

工作一年半在职跳槽,分享一波面经+经验,求加精

   
全局:
google onsite 3. 扫一遍string 用一个map存index。
能快一些。但总觉得是不是哪里还是麻烦了?有更好的方法么

  1.     public String solve2(String str, String[] words){
  2.         Map<Character, LinkedList<Integer>> map = process(str);
  3.         int max = 0;
  4.         String res = "";
  5.         for(String ss: words){
  6.             if(ss.length() > max){
  7.                 Map<Character, LinkedList<Integer>> tmp = copyMap(map);
  8.                 int cur = 0;
  9.                 boolean flag = true;
  10.                 for(char c: ss.toCharArray()){
  11.                     if(!tmp.containsKey(c) || tmp.get(c).size()==0){
  12.                         flag = false;
  13.                         break;
  14.                     }
  15.                     int p = tmp.get(c).pollFirst();
  16.                     if( p < cur ){
  17.                         flag = false;
  18.                         break;
  19.                     }
  20.                     cur = p;
  21.                 }
  22.                 if(flag){
  23.                     max = ss.length();
  24.                     res = ss;
  25.                 }
  26.             }
  27.         }
  28.         return res;
  29.     }

  30.     private Map<Character, LinkedList<Integer>> copyMap(Map<Character, LinkedList<Integer>> map){
  31.         Map<Character, LinkedList<Integer>> tmp = new HashMap<>();
  32.         for(Map.Entry<Character, LinkedList<Integer>> me: map.entrySet()){
  33.             tmp.put(me.getKey(), new LinkedList<>(me.getValue()));
  34.         }
  35.         return tmp;
  36.     }

  37.     private Map<Character, LinkedList<Integer>> process(String str){
  38.         Map<Character, LinkedList<Integer>> map = new HashMap<>();
  39.         char[] chars = str.toCharArray();
  40.         for(int i = 0; i<chars.length; i++){
  41.             map.computeIfAbsent(chars[i], k->new LinkedList<Integer>()).add(i);
  42.         }
  43.         return map;
  44.     }
复制代码



String[] strs1 = {"a","aae","bc","adbe","abe","bca","aaaa"};
Solution5 s = new Solution5();
String res = s.solve2("abcde", strs1);  -----> abe

补充内容 (2017-1-6 09:44):
尤其用林kedlist存相同字母的每个index 和copymap哪里。不知道有没有什么更好的方法?


回复

使用道具 举报

🔗
 楼主| shabixia 2017-1-7 02:34:36 | 只看该作者
全局:
gameboyying 发表于 2017-1-6 08:46
给你一个folder的路径,然后写个method删除该folder下所有内容相同的文件

这个怎么写? 有代码吗?

写个class,实现几个method,大概意思意思,配合少量伪代码
回复

使用道具 举报

🔗
 楼主| shabixia 2017-1-7 02:43:10 | 只看该作者
全局:
吃啥才算成熟 发表于 2017-1-6 09:43
google onsite 3. 扫一遍string 用一个map存index。
能快一些。但总觉得是不是哪里还是麻烦了?有更好的方 ...

没仔细想过额,当时我给出这个面试官就很满意了。。。PS:层主好认真!
回复

使用道具 举报

全局:
想问下lz跳槽什么时候跳槽最好..等0.5年,还是1年/1.5/2年比较好?
回复

使用道具 举报

🔗
wzrthhj 2017-6-10 13:32:31 | 只看该作者
全局:
运气也太好了吧,都是原题。。。。。5555
回复

使用道具 举报

全局:
前辈好!想问一下在亚麻是lv5了吗 申Google的时候是投的就是T4?很厉害啊 谢谢!
回复

使用道具 举报

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

本版积分规则

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