注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
3月25日
Pinterst第一次电面,白人大叔
代码,就是计算器,加减小括号和字母变量,我没写完
结束之后又花了五十分钟在eclips上写完了,以下是正确的代码。造福大众
import java.io.*;
import java.util.*;
/*
* To execute Java, please define "static void main" on a class
* named Solution.
*
* If you need more classes, simply define them inline.
You are building an educational website and want to create a simple calculator for students to use. The calculator will only allow addition and subtraction of positive integers.
Given an expression string using the "+" and "-" operators like "5+16-2", write a function to parse the string and returns the result.
Sample input/output:
"6+9-12" => 3
"1+2-3+4-5+6-7" => -2
We also want to allow parentheses in our input. Given an expression string using the "+", "-", "(", and ")" operators like "5+(16-2)", write a function to parse the string and evaluate the result.
Sample input:
expression1 = "5+16-((9-6)-(4-2))"
expression2 = "22+(2-4)"
Sample output:
evaluate(expression1) => 20
evaluate(expression2) => 20
We want to allow students to use variables when entering expressions in the calculator. In addition to the formula string, we’ll add a new input to our function that holds variables and their values:
{"e": 8, "y": 7, "pressure": 5}
and our string inputs now have a format like
"(e+3)-temperature-pressure+2".
Evaluate the formula result as fully as possible using the input variables. It is possible that not all variables have known values, in which case you should preserve them in the output.
Sample input:
variables = {"e": 8, "y": 7, "pressure": 5}
expression = "(e+3)-temperature-prr);
res+=flag*sign*corr_num;
}else{
if(!map.containsKey(substr)){
map.put(substr,flag*sign);
}else{
map.put(substr,map.get(substr)+flag*sign);
}
}
}
// output
StringBuilder sb = new StringBuilder();
sb.append(res);
for( String str:map.keySet() ){
if(map.get(str)==0){
continue;
}
if(map.get(str)==1){
sb.append("+");
}else if(map.get(str)==-1){
sb.append("-");
}else if(map.get(str)>0){
sb.append("+");
sb.append(map.get(str)+ "*");
}else { //map.get(str)<0
sb.append(map.get(str)+ "*");
}
sb.append(str);
}
return sb.toString();
}
private int getNum(String str,Map<String, Integer> var){
return var.get(str);
}
}
/*
Your previous Markdown content is preserved below:
Welcome to the Interview!
*/
我作大死,3.27申请了二次机会。
一个印度三哥,八年工作经验,问了最大的挑战什么的,交流一般。总是感觉他不满意我的回答,耽误了一些时间。
然后开始是很简单的矩阵找 长方形区域0,就是很简单啦,不过我没注意他的定义,耽误了一点时间。
然后就是求岛屿个数原题,我BFS,时间有点紧,强行写完了,一运行有bug。
过了两天通知挂了。
也是自己准备不足,岛屿个数都没写完。也是之前耽误时间了。我发现真的是耽误一点时间都不行。唉。继续努力。今天刚面完脸熟的电面,面完就把面试官举报了。下周一狗家昂塞。加油
|