coder
(coder)
2019 年9 月 13 日 05:39
1
刚刚做完推特的OA,花了2.5小时,感觉没戏了。
做到后半段才看到这个链接。。。囧
相关链接:Twitter OA 新题
我遇到了这4题。
Restocking the Warehouse
Coloring the blocks (Lintcode 515. Paint House)
Reaching Points (Leetcode 780. Reaching Points)
Twitter Social Network (Leetcode 547. Friend Circles)
其中,第一题是上面的归纳里没有的,补充一下。
这题没找到原题,但很简单,可以秒了。
预祝其他同学们OA顺利。
2 个赞
匿名1266
(匿名1266)
2019 年9 月 25 日 07:23
4
Taken from https://leetcode.com/problems/paint-house/
public static int minPrice(List<List<Integer>> cost) {
// Write your code here
if( null == cost || cost.size() == 0)
return 0;
for(int i = 1 ; i < cost.size(); i++){
int x = cost.get(i).get(0) + Math.min(cost.get(i-1).get(1),cost.get(i-1).get(2)) ;
cost.get(i).set(0, x);
int y = cost.get(i).get(1) + Math.min(cost.get(i-1).get(0),cost.get(i-1).get(2)) ;
cost.get(i).set(1, y);
int z = cost.get(i).get(2) + Math.min(cost.get(i-1).get(1),cost.get(i-1).get(0)) ;
cost.get(i).set(2, z);
}
int m = cost.size() - 1;
return Math.min(Math.min(cost.get(m).get(0), cost.get(m).get(1)), cost.get(m).get(2));
}
匿名1266
(匿名1266)
2019 年9 月 25 日 07:23
5
Given a list of events per team for a Football match, return the chronological order of the game events, using a set of ugly string comparisons and unncessarily complicated problem statement. But here you go, works for all cases:
class Result {
static class Score{
int actualTime;
String timeString;
String teamName;
String playerName;
String substituteName;
char eventType;
boolean isFirstHalf;
public Score(int actualTime, String timeString, String teamName,String playerName,String substituteName,char eventType, boolean isFirstHalf){
this.actualTime = actualTime;
this.timeString = timeString;
this.teamName = teamName;
this.playerName = playerName;
this.substituteName = substituteName;
this.eventType = eventType;
this.isFirstHalf = isFirstHalf;
}
public String toString(){
return actualTime + " " + timeString + " " + teamName + " " + playerName +" " + substituteName + " "+ eventType +
" " + isFirstHalf;
}
public String getOutputString(){
return this.teamName +" " + this.playerName + " " + this.timeString + " " + this.eventType + " " + this.substituteName;
}
}
static Map<Character, Integer> map = new HashMap<>();
public static List<String> getEventsOrder(String team1, String team2, List<String> events1, List<String> events2) {
map.put('G', 1);
map.put('Y', 2);
map.put('R', 3);
map.put('S', 4);
List<Score> scores = new ArrayList<>();
for(String e1: events1){
Score score = parseString(e1, team1);
scores.add(score);
System.out.println(score);
}
for(String e2: events2){
Score score = parseString(e2, team2);
scores.add(score);
System.out.println(score);
}
Collections.sort(scores, new Comparator<Score>(){
public int compare(Score s1, Score s2){
if(s1.isFirstHalf== true && s2.isFirstHalf==false){
return -1;
}
if(s1.isFirstHalf== false && s2.isFirstHalf==true){
return 1;
}
if(s1.actualTime != s2.actualTime)
return s1.actualTime - s2.actualTime;
if(map.get(s1.eventType)!= map.get(s2.eventType)){
return map.get(s1.eventType)- map.get(s2.eventType);
}
if(!s1.teamName.equals(s2.teamName))
return s1.teamName.compareTo(s2.teamName);
return s1.playerName.compareTo(s2.playerName);
}
});
List<String> answer = new ArrayList<>();
for(Score score: scores){
answer.add(score.getOutputString().trim());
}
return answer;
}
public static Score parseString(String str, String team){
String[] words = str.split(" ");
int time = getTimeIndex(words);
char event = words[time+1].charAt(0);
String player = "";
for(int i=0;i<time;i++){
player = player + " " + words[i];
}
player = player.trim();
String sub = "";
if(event=='S'){
for(int i =time+2;i<words.length;i++){
sub += words[i] + " ";
}
sub = sub.trim();
}
int actualTime =0;
boolean isFirstHalf = false;
if(words[time].contains("+")){
String timeSplit[] = words[time].split("\\+");
actualTime += Integer.parseInt(timeSplit[0]);
if(actualTime <= 45){
isFirstHalf = true;
}
actualTime += Integer.parseInt(timeSplit[1]);
}else{
actualTime += Integer.parseInt(words[time]);
if(actualTime <= 45){
isFirstHalf = true;
}
}
Score score = new Score(actualTime, words[time], team, player, sub, event, isFirstHalf);
return score;
}
public static int getTimeIndex(String[] words){
for(int i =0;i<words.length;i++){
if(words[i].charAt(0)>='0' && words[i].charAt(0)<='9'){
return i;
}
}
return -1;
}
}
818
2019 年10 月 5 日 23:04
6
刚刚做完twitter的白嫖OA第一题是非常简单的找一个位置,它前面的和等于后面的和。略过。。。。
第二题是买票,就一人买一张票, 比如一个数组 1,2,3,4,5 你是3, 一人一次买一张,求你需要过多少个时间才能买的玩。
假如你是3, 那就一共1+2+3+2+2 = 10 个时间
思路是前面的算比3大算3,比3小算自己, 后面的比3大算2, 比三小算自己
第三题,给两个string,问最少换多少个字符才能两个string相等
第四题,喷水题
大概一个小时不到做完,可以先去leetcode看,题目都比较简单,楼主用的是c++