📣 独立日限时特惠: VIP通行证立减$68
楼主: tianz
跳转到指定楼层
上一主题 下一主题
收起左侧

Uber phone+onsite

🔗
frederickyl 2015-8-16 14:32:58 | 只看该作者
全局:
楼主能说下reverse string那道题的思路吗?多谢!
回复

使用道具 举报

🔗
DIMfang 2015-8-22 21:17:59 | 只看该作者
全局:
yingchal 发表于 2015-7-21 15:39
感谢~目前为止最清晰的解释!赞!
那reverse words的变种~应该如何approach阿?我目前想到的方法都不 ...

public static void main(String[] args) {
            
            String[] a1 = {"this", ",", "is", "a", "word", "."};
            String b = reverseString1(a1);
            System.out.println(b);
          }
          public static String reverseString1(String[] s) {
                  Stack<String> stack1= new Stack<String>();
                  Stack<String> stack2= new Stack<String>(); //仅存储
                  StringBuilder res = new StringBuilder(); //输出用
                  Map<Integer, String> map = new HashMap<Integer, String>();//存储标点位置
                  for (int i = 0; i <= s.length - 1; i++) {
                          if (s[i].equals(",") || s[i].equals(".")) {
                                  if (s[i].equals(",")){
                                         map.put(i, ",");
                                     continue;
                                  } else if (s[i].equals(".")) {
                                         map.put(i, ".");
                                         continue;
                                  }
                          }
                          stack1.push(s[i]);
                  }
                  
                  for (int i = 0; i <= s.length - 1; i++) {
                          if (map.containsKey(i)) {
                                  String temp = map.get(i);
                                  stack2.push(temp);
                                  res.append(temp).append(" ");
                                  continue;
                          }
                          if (map.containsKey(i + 1)) {//如果下一个是标点的话,后面就不要加空格了
                                  res.append(stack1.peek());
                                  stack2.push(stack1.pop());
                          } else {
                                  res.append(stack1.peek()).append(" ");
                                  stack2.push(stack1.pop());
                          }
                  }
                  
                  return res.toString();
          
          }
回复

使用道具 举报

🔗
DIMfang 2015-8-22 21:18:22 | 只看该作者
全局:
frederickyl 发表于 2015-8-16 14:32
楼主能说下reverse string那道题的思路吗?多谢!

public static void main(String[] args) {
            
            String[] a1 = {"this", ",", "is", "a", "word", "."};
            String b = reverseString1(a1);
            System.out.println(b);
          }
          public static String reverseString1(String[] s) {
                  Stack<String> stack1= new Stack<String>();
                  Stack<String> stack2= new Stack<String>(); //仅存储
                  StringBuilder res = new StringBuilder(); //输出用
                  Map<Integer, String> map = new HashMap<Integer, String>();//存储标点位置
                  for (int i = 0; i <= s.length - 1; i++) {
                          if (s[i].equals(",") || s[i].equals(".")) {
                                  if (s[i].equals(",")){
                                         map.put(i, ",");
                                     continue;
                                  } else if (s[i].equals(".")) {
                                         map.put(i, ".");
                                         continue;
                                  }
                          }
                          stack1.push(s[i]);
                  }
                  
                  for (int i = 0; i <= s.length - 1; i++) {
                          if (map.containsKey(i)) {
                                  String temp = map.get(i);
                                  stack2.push(temp);
                                  res.append(temp).append(" ");
                                  continue;
                          }
                          if (map.containsKey(i + 1)) {//如果下一个是标点的话,后面就不要加空格了
                                  res.append(stack1.peek());
                                  stack2.push(stack1.pop());
                          } else {
                                  res.append(stack1.peek()).append(" ");
                                  stack2.push(stack1.pop());
                          }
                  }
                  
                  return res.toString();
          
          }
回复

使用道具 举报

🔗
cool19910110 2015-8-23 07:04:00 | 只看该作者
全局:
好东西赞一个~
回复

使用道具 举报

🔗
bluestarwing 2015-8-27 05:22:52 | 只看该作者
全局:
lz面的什么组啊
回复

使用道具 举报

🔗
swly 2015-8-27 17:55:16 | 只看该作者
全局:
感谢分享!感觉lz是个牛
回复

使用道具 举报

🔗
pikachu123 2015-9-4 10:53:22 | 只看该作者
全局:
楼主是CMU哪个program的啊?
回复

使用道具 举报

🔗
tiantiana 2015-9-4 11:01:24 | 只看该作者
全局:
lz加油!这个设计题,没做过也容易摸不到头脑。
回复

使用道具 举报

🔗
ronaldo17 2015-9-4 11:24:53 | 只看该作者
全局:
lz能不能解释下uber eat是什么意思?有哪些requirements呀?
回复

使用道具 举报

🔗
spiritrhy 2015-10-20 13:48:36 | 只看该作者
全局:
楼主面的是 growth supply-backend吗
回复

使用道具 举报

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

本版积分规则

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