由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - L家电面
相关主题
L二电面据,附面经写一个function判断一个数是不是2的整数次方
leetcoede新题Valid PalindromeLeetCode上word search问题的几个例子不对
用有限状态机写了一下leetcode valid numberfacebook的面试题
写了一下leetcode上Valid Number,用boolean表示一些状态是不是比较简单请教一道leetcode的新题
秒杀valid numberinterleave string 的题目
valid number这道题看到有人用有限状态机做 太牛不敢看关于atoi的overflow
facebook电面题目palindrome partioning II
[合集] G家onsite面经发现valid number真是必杀题
相关话题的讨论汇总
话题: str话题: state话题: return话题: index话题: false
进入JobHunting版参与讨论
1 (共1页)
l****i
发帖数: 2772
1
刚结束,一个三哥,一个老中。老中是senior,三哥主持。呵呵,口音一如既往的重。
2个老题,第一题字符串是否是数字,第二题判断一个数字,是否在旋转过的排序数组
中。
j*****y
发帖数: 1071
2
老中问问题 ?

【在 l****i 的大作中提到】
: 刚结束,一个三哥,一个老中。老中是senior,三哥主持。呵呵,口音一如既往的重。
: 2个老题,第一题字符串是否是数字,第二题判断一个数字,是否在旋转过的排序数组
: 中。

l****i
发帖数: 2772
3
老中不怎么说话,偶尔问2个问题。
HR之前说是有2个面试人,他们在培训新人面试。所以应该是老印在被培训面试。老中
负责。不过全程是老印在主持。

【在 j*****y 的大作中提到】
: 老中问问题 ?
j*****y
发帖数: 1071
4
字符串是否是数字, 和leetcode上一样的题目吗?

【在 l****i 的大作中提到】
: 刚结束,一个三哥,一个老中。老中是senior,三哥主持。呵呵,口音一如既往的重。
: 2个老题,第一题字符串是否是数字,第二题判断一个数字,是否在旋转过的排序数组
: 中。

l****i
发帖数: 2772
5
当场问了三哥是否考虑e的情况,回答不用。总体比leetcode上那个简单。

【在 j*****y 的大作中提到】
: 字符串是否是数字, 和leetcode上一样的题目吗?
w****x
发帖数: 2483
6

leetcode那题几乎是我见到过最难的了

【在 j*****y 的大作中提到】
: 字符串是否是数字, 和leetcode上一样的题目吗?
P*******b
发帖数: 1001
7
第二题有重复还是没有重复元素?

【在 l****i 的大作中提到】
: 刚结束,一个三哥,一个老中。老中是senior,三哥主持。呵呵,口音一如既往的重。
: 2个老题,第一题字符串是否是数字,第二题判断一个数字,是否在旋转过的排序数组
: 中。

l****i
发帖数: 2772
8
刚结束,一个三哥,一个老中。老中是senior,三哥主持。呵呵,口音一如既往的重。
2个老题,第一题字符串是否是数字,第二题判断一个数字,是否在旋转过的排序数组
中。
j*****y
发帖数: 1071
9
老中问问题 ?

【在 l****i 的大作中提到】
: 刚结束,一个三哥,一个老中。老中是senior,三哥主持。呵呵,口音一如既往的重。
: 2个老题,第一题字符串是否是数字,第二题判断一个数字,是否在旋转过的排序数组
: 中。

l****i
发帖数: 2772
10
老中不怎么说话,偶尔问2个问题。
HR之前说是有2个面试人,他们在培训新人面试。所以应该是老印在被培训面试。老中
负责。不过全程是老印在主持。

【在 j*****y 的大作中提到】
: 老中问问题 ?
相关主题
valid number这道题看到有人用有限状态机做 太牛不敢看写一个function判断一个数是不是2的整数次方
facebook电面题目LeetCode上word search问题的几个例子不对
[合集] G家onsite面经facebook的面试题
进入JobHunting版参与讨论
j*****y
发帖数: 1071
11
字符串是否是数字, 和leetcode上一样的题目吗?

【在 l****i 的大作中提到】
: 刚结束,一个三哥,一个老中。老中是senior,三哥主持。呵呵,口音一如既往的重。
: 2个老题,第一题字符串是否是数字,第二题判断一个数字,是否在旋转过的排序数组
: 中。

l****i
发帖数: 2772
12
当场问了三哥是否考虑e的情况,回答不用。总体比leetcode上那个简单。

【在 j*****y 的大作中提到】
: 字符串是否是数字, 和leetcode上一样的题目吗?
w****x
发帖数: 2483
13

leetcode那题几乎是我见到过最难的了

【在 j*****y 的大作中提到】
: 字符串是否是数字, 和leetcode上一样的题目吗?
P*******b
发帖数: 1001
14
第二题有重复还是没有重复元素?

【在 l****i 的大作中提到】
: 刚结束,一个三哥,一个老中。老中是senior,三哥主持。呵呵,口音一如既往的重。
: 2个老题,第一题字符串是否是数字,第二题判断一个数字,是否在旋转过的排序数组
: 中。

s***5
发帖数: 2136
15
第一题用Perl regular expression可以一行搞定。
if(str =~ /[+|-]?[0|[1-9]\d*](\.[0-9]+)*/ || str =~ /[+|-]?\.\d+/)
return true;
else
return false;
如果不能用regular expression,下面有个C++的code。
bool isNumeric(string str)
{
// assume there are no leading or ending spaces in the string
int i = 0, end = str.size()-1;
if(str[i] == '+' || str[i] == '-') i++; // check the sign symbol

if(str[i] == '.') { // if the first non-sign char is '.', e.g. .56
if(i == end) return false; // not numeric if no digits after
the '.' symbol
i++;
}
else if(str[i] == '0') { // if the first non-sign char is 0, e.g. 0.
45
if(i == end) return true; // check special cases: +0, -0, 0
i++;
if(str[i] != '.' || i == end) return false; // not numeric if
no digits after the '.' symbol
else i++;
}
else if(str[i] > 48 && str[i] <= 57) { // if the first non-sign char
is 1~9
i++;
while(i <= end) {
if(str[i] == '.') {
if(i == end) return false; // not numeric if no digits
after the '.' symbol
i++;
break;
}
else if(str[i] < 48 || str[i] > 57)
return false;
i++;
}
}
else
return false;

while(i <= end) { // process the digits after the '.' symbol
if(str[i] < 48 && str[i] > 57)
return false;
i++;
}
return true;
}
z*******3
发帖数: 13709
16
是否是数字,一行就够咯
Double.parseDouble(String);
z*******3
发帖数: 13709
17
尼玛,谁在挖坟?
p*****2
发帖数: 21240
18

我觉得leetcode上边这题很坑爹。

【在 w****x 的大作中提到】
:
: leetcode那题几乎是我见到过最难的了

c********p
发帖数: 1969
19
mark
r*c
发帖数: 167
20
二爷,坑爹算法来也。用状态机搞砸一切面面!哈哈
#include
#include
#include
using namespace std;
class Numericality;
void TestNumericality();
void TestNumericalityHelper(const string& str, const bool expected,
Numericality& nc);
class Numericality
{
public:
struct State
{
const string _str;
int _index;
State() {}
State(string s, int i) : _str(s), _index(i){}
virtual State* MoveNext(){
if(_str.empty() || _index < 0 || _index >= _str.length())
return new RejectState();
if(_str.at(_index) == '+' || _str.at(_index) == '-')
return new SignState(_str, _index+1);
else if(_str.at(_index) == '.')
return new FirstDotState(_str, _index);
else if(isdigit( _str.at(_index)))
return new DigitPlusState(_str, _index+1);
else
return new RejectState();
}
virtual bool isRejected(){return false;}
};
struct RejectState : public State
{
RejectState(): State(){}
State* MoveNext(){return 0;}
bool isRejected(){return true;}
};
struct AcceptState : public State
{
AcceptState(): State(){}
State* MoveNext(){return 0;}
};
struct SignState : public State
{
SignState(string s, int i) : State(s, i){}
State* MoveNext(){
if(_str.at(_index) == '.')
return new FirstDotState(_str, _index);
else if(isdigit( _str.at(_index)))
return new DigitPlusState(_str, _index+1);
else
return new RejectState();
}
};
struct FirstDotState : public State
{
FirstDotState(string s, int i):State(s, i){}
State* MoveNext(){
if(_str.length() == 2)
return new RejectState();
else if(isdigit( _str.at(_index + 1)))
return new DigitPlusState(_str, _index+1);
else
return new RejectState();
}
};
struct SecondDotState : public State
{
SecondDotState(string s, int i):State(s, i){}
State* MoveNext(){
if(isdigit( _str.at(_index)))
return new DigitPlusState(_str, _index+1);
else
return new RejectState();
}
};
struct DigitPlusState : public State
{
DigitPlusState(string s, int i) : State(s, i){}
State* MoveNext(){
if(_index == _str.length()) //all char used up
return new AcceptState();
else if(isdigit( _str.at(_index)))
return new DigitPlusState(_str, _index+1);
else if(_str.at(_index) == '.')
return new SecondDotState(_str, _index + 1);
else
return new RejectState();
}
};
bool isNumeric(string str)
{
State *pState = new State(str, 0);
while(pState->_index <= str.length()-1)
{
State *pTemp = pState;
pState = pState->MoveNext();
delete pTemp;
if(pState->isRejected()) return false;
}
if(pState->isRejected()) return false;
return true;
}
bool isNumeric_mitbbs(string str) //unfortunately this is a buggie
function
{
// assume there are no leading or ending spaces in the string
int i = 0, end = str.size()-1;
if(str[i] == '+' || str[i] == '-') i++; // check the sign
symbol
if(str[i] == '.') { // if the first non-sign char is '.', e.g. .
56
if(i == end) return false; // not numeric if no digits
after the '.' symbol
i++;
}
else if(str[i] == '0') { // if the first non-sign char is 0, e.g
. 0.45
if(i == end) return true; // check special cases: +0, -0, 0
i++;
if(str[i] != '.' || i == end) return false; // not
numeric if no digits after the '.' symbol
else i++;
}
else if(str[i] > 48 && str[i] <= 57) { // if the first non-sign
char is 1~9
i++;
while(i <= end) {
if(str[i] == '.') {
if(i == end) return false; // not numeric if no
digits after the '.' symbol
i++;
break;
}
else if(str[i] < 48 || str[i] > 57)
return false;
i++;
}
}
else
return false;
while(i <= end) { // process the digits after the '.' symbol
if(str[i] < 48 && str[i] > 57)
return false;
i++;
}
return true;
}
};
void TestNumericality()
{
Numericality nc;
string str("+2345");
TestNumericalityHelper(str, true, nc);
assert(nc.isNumeric("+2345"));
str = "-2345";
TestNumericalityHelper(str, true, nc);
str = "2345.2345";
TestNumericalityHelper(str, true, nc);
str = "-.2345.2345";
TestNumericalityHelper(str, true, nc);
str = "+.987.123";
TestNumericalityHelper(str, true, nc);
str = "-..987.123";
TestNumericalityHelper(str, false, nc);
str = "-93j123";
TestNumericalityHelper(str, false, nc);
str = "-76532.";
TestNumericalityHelper(str, false, nc);
str = "2345.23.5";
TestNumericalityHelper(str, false, nc);
}
void TestNumericalityHelper(const string& str, const bool expected,
Numericality& nc)
{
cout<<"Now testing "< "false")< bool result = nc.isNumeric(str);
bool result_mitbbs = nc.isNumeric_mitbbs(str);
cout<<"result: "<<(result ? "true" : "false") <<"; mitbbs method: "<<(
result_mitbbs ? "true" : "false")< }

【在 p*****2 的大作中提到】
:
: 我觉得leetcode上边这题很坑爹。

h******3
发帖数: 351
21
用google doc写code?电面之前要做online test么?

【在 l****i 的大作中提到】
: 刚结束,一个三哥,一个老中。老中是senior,三哥主持。呵呵,口音一如既往的重。
: 2个老题,第一题字符串是否是数字,第二题判断一个数字,是否在旋转过的排序数组
: 中。

1 (共1页)
进入JobHunting版参与讨论
相关主题
发现valid number真是必杀题秒杀valid number
一个小题目valid number这道题看到有人用有限状态机做 太牛不敢看
我觉得valid number其实并不难facebook电面题目
请教个面试题[合集] G家onsite面经
L二电面据,附面经写一个function判断一个数是不是2的整数次方
leetcoede新题Valid PalindromeLeetCode上word search问题的几个例子不对
用有限状态机写了一下leetcode valid numberfacebook的面试题
写了一下leetcode上Valid Number,用boolean表示一些状态是不是比较简单请教一道leetcode的新题
相关话题的讨论汇总
话题: str话题: state话题: return话题: index话题: false