推荐:数据科学课程和书籍清单以及培训讲座


一亩三分地论坛

 找回密码
 获取更多干活,快来注册

一亩三分地官方iOS手机应用下载
查看: 657|回复: 4
收起左侧

Linkedin 店面 8/1

[复制链接] |试试Instant~ |关注本帖
perkinli 发表于 2017-8-2 06:02:52 | 显示全部楼层 |阅读模式

2017(7-9月) 码农类 硕士 全职@Linkedin - 猎头 - 技术电面 |Other在职跳槽

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

您需要 登录 才可以下载或查看,没有帐号?获取更多干活,快来注册

x
/*
* Returns true if the input string is a number and false otherwise
*/
//-10,10, 1. 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
//10, 1.0 , 0.1, -2
// .5. 1point3acres.com/bbs
public boolean isNumber(String toTest)
{
    // implementation here.1point3acres缃
    String str = toTest.trim();
    boolean hasNumberBefore = false;. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
    boolean hasPointBefore = false;
    for (int i = 0; i < str.length(); i++) {
        char curr = str.charAt(i);
        if (curr == '-' && i != 0) {
            return false;
        } else if (Character.isDigit(curr)) {
            hasNumberBefore = true;
        } else if (curr == '.') {
            if (hasNumberBefore == false || hasPointBefore == true) {
                return false;
            }
            hasPointBefore = true;
        } else {
            return false;
        }
    }
    return hasNumberBefore;
}

. 1point3acres.com/bbs

/* This class will be given a list of words (such as might be tokenized
* from a paragraph of text), and will provide a method that takes two
. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴 * words and returns the shortest distance (in words) between those two
* words in the provided text.
* Example:
*   WordDistanceFinder finder = new WordDistanceFinder(Arrays.asList("the", "quick", "brown", "fox", "quick")); 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
*   assert(finder.distance("fox", "the") == 3);
*   assert(finder.distance("quick", "fox") == 1); 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
*. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
* "quick" appears twice in the input. There are two possible distance values for "quick" and "fox": 鏉ユ簮涓浜.涓夊垎鍦拌鍧.
*     (3 - 1) = 2 and (4 - 3) = 1.
* Since we have to return the shortest distance between the two words we return 1.
*/
public class WordDistanceFinder {
    Map<String, List<Integer>> wordIndex = new HashMap<>();. 鍥磋鎴戜滑@1point 3 acres
    public WordDistanceFinder (List<String> words) {
        // implementation here
        for (int i = 0; i < words.size(); i++) {. from: 1point3acres.com/bbs
            String curr = words.get(i);. more info on 1point3acres.com
            if (!wordIndex.containKey(curr)) {
                wordIndex.put(curr, new ArrayList<Integer>());
            }
            wordIndex.get(curr).add(i);//fox 3 the 0, quick1, 4 fox 3
        }
    }
    public int distance (String wordOne, String wordTwo) {
        // implementation here
        if (wordOne.equals(wordTwo)) {
            return 0;
        }
        List<Integer> indexOne = wordIndex.get(wordOne);
        List<Integer> indexTwo = wordIndex.get(wordTwo);. 鐣欏鐢宠璁哄潧-涓浜╀笁鍒嗗湴
        int index1 = 0, index2 = 0, min = Integer.MAX_VALUE;
        while (index1 < indexOne.size() && index2 < indexTwo.size()) {
            int curr1 = indexOne.get(index1), curr2 = indexTwo.get(index2);
            if (curr1 < curr2) {
                min = Maht.min(min, curr2 - curr1);
                index1++;.1point3acres缃
            } else {. From 1point 3acres bbs
                min = Maht.min(min, curr1 - curr2);
                index2++;
            }
        }
       return min;
    }
}. 涓浜-涓夊垎-鍦帮紝鐙鍙戝竷

鏉ユ簮涓浜.涓夊垎鍦拌鍧.

评分

3

查看全部评分

影子冷峰 发表于 2017-8-4 09:49:01 | 显示全部楼层
谢谢楼主分享! 楼主应该拿到on-site 了吧
回复 支持 反对

使用道具 举报

 楼主| perkinli 发表于 2017-8-4 10:50:55 | 显示全部楼层
影子冷峰 发表于 2017-8-4 09:49
谢谢楼主分享! 楼主应该拿到on-site 了吧
. 1point3acres.com/bbs
还没, 还有在一轮的店面
回复 支持 反对

使用道具 举报

lli 发表于 2017-8-11 12:27:59 | 显示全部楼层
I think 00 is not a valid number
回复 支持 反对

使用道具 举报

kqxqx 发表于 昨天 04:41 | 显示全部楼层
第一题好像是李特口德 陆武 吧?corner case居多,要bug free其实很难
回复 支持 反对

使用道具 举报

本版积分规则

关闭

一亩三分地推荐上一条 /5 下一条

手机版|小黑屋|一亩三分地论坛声明

custom counter

GMT+8, 2017-8-22 23:06

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

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