由买买提看人间百态

topics

全部话题 - 话题: char
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)
i**********e
发帖数: 1145
1
Are you going to interview candidates soon?
StrStr implementation is much easier to solve compared to wildcard matching.
Although the wildcard matching is a very tricky question, Facebook had asked
this question before:
http://www.mitbbs.com/article_t/JobHunting/31575425.html
If you have taken part in Google Codejam before, you will know how fast
those crazy smart people solve problems within minutes. To solve this
problem using nothing but paper and pencil + without bugs in 20 minutes is
very v... 阅读全帖
i**********e
发帖数: 1145
2
另外,这是我的重写的新代码,我觉得比我之前的版本要简洁些。
而且这版本也处理'.'为一个任意字母。
bool match(const char *str, const char *pattern) {
const char *p1 = pattern, *p2 = str;
// If the first character is a letter, need to match letter by letter.
while (*p1 != '*') {
if (!*p1 && !*p2) return true;
if (!*p1 || !*p2) return false;
if (*p1 == '.' || *p1 == *p2) {
p1++;
p2++;
} else {
return false;
}
}
while (true) {
// Now *p1 must be '*'
while (*p1 && *p1 == '*') {
p1++;
... 阅读全帖
j*****g
发帖数: 223
3
总结一下面试的准备活动,希望有帮助.
==================== AREAS/TOPICS to study/prep/review ====================
复习的东西还挺多的。比不过刚毕业的呀 :), 脑子不好使了,东西也差不多忘光了...
嘿嘿....
• Sorting
o Bubble/select/insertion/counting/qsort/heap/merge/bst
o Time/space complexity analysis
• Caching design
o Replacement policy (LRU, LFU, NRU, etc…)
o Efficiency/complexity/performance
o Distributed cache
o Hashing
• Multi-thread
o Locking/mutex/semaphore/critical sec... 阅读全帖
j*****g
发帖数: 223
4
总结一下面试的准备活动,希望有帮助.
==================== AREAS/TOPICS to study/prep/review ====================
复习的东西还挺多的。比不过刚毕业的呀 :), 脑子不好使了,东西也差不多忘光了...
嘿嘿....
• Sorting
o Bubble/select/insertion/counting/qsort/heap/merge/bst
o Time/space complexity analysis
• Caching design
o Replacement policy (LRU, LFU, NRU, etc…)
o Efficiency/complexity/performance
o Distributed cache
o Hashing
• Multi-thread
o Locking/mutex/semaphore/critical sec... 阅读全帖
i**********e
发帖数: 1145
5
来自主题: JobHunting版 - 攒人品 报BB面经
void foo(char** a){
*a = "hello world";
}
int main(){
char* c;
foo(&c);
printf("%s",c);
return 0;
}
这个程序有两个错误。
1) *a = "hello world";
This syntax is incorrect. The only exception is during intialization of a C-
style string constant like this: char *a = "hello world"; Note that this is a C-style string constant, if you try to modify the string, the result is undefined.
In this case, you should use strcpy(a, "hello world");
2) c is a pointer to a char. Since it is not initiali... 阅读全帖
E*****7
发帖数: 128
6
来自主题: JobHunting版 - C++ 面试题
class String
{
public:
String(const char*);
String();
friend int strcmpu(const String& lhs, const String& rhs);
private:
char* s;
int len;
};
// Implementation for it to compile("Big Three" issue exists)
#include
class String
{
public:
String(const char* in_s)
{
if (in_s)
{
s = new char[strlen(in_s) + 1];
strcpy(s, in_s);
} else {
String();
}
}
String()
{
s = 0;
len = 0;
}
friend int strcmpu(const String& lhs, const String& rhs);
private:
char* s;
... 阅读全帖
j****k
发帖数: 91
7
来自主题: JobHunting版 - 请问这样写程序错了吗?
二楼应该是这个题目的正解.
但是如果稍微改一下题目, 把pString1,2的定义改为:
char *pString1, *pString2;
pString1 = (char *)malloc(3*sizeof(char));
pString2 = (char *)malloc(21*sizeof(char));
strcpy(pString1,"AAA");
strcpy(pString2,"BBBBBBBBBBBBBBBBBBBB");
这样在for循环里走过第三步的时候pString1就已经到头了, 但为什么接下来的循环都
不会出错? 虽然说c++没有边界检测, 但程序在修改pString1越界指向的内容, 这难道
不该是Access violation吗?
g*******s
发帖数: 490
8
来自主题: JobHunting版 - 网上c sample question的一堆错误
这边的c sample question
http://www.bestsamplequestions.com/technical-questions/c-sample-questions/c-sample-questions.html
列一下我发现的错误
第8
system dependent, be cautious of all sizeof questions, most of them are
system dependent
第10
system dependent, depends on the size of int
第11
compiler dependent
it's fine. 其实即使function的argument是数组形式,compiler也会自动改成指针,
just remember array is always
passed by its pointer in function calls
第16
won't print anything, 两个指针都没有allocate memory
第18
for declaration, it is not g... 阅读全帖
c***2
发帖数: 838
9
来自主题: JobHunting版 - Microsoft screening programming problem
int strdis(const char *str, char ch1, char ch2, int n)
{
const char *pf;
const char *p=str;

if(!str)
return 0;

while(*p){
while((*p)&&(*p!=ch1)&&(*p!=ch2)) p++;
if(!(*p)) return 0;
if(*p==ch1){
pf=p;
while(*p&&(*p!=ch2)) p++;
if(!(*p)) return 0;
if(p-pf<=n)
return 1;
//wind back
p=pf+1;
}
else{
pf=p;
while(*p&&(*p!... 阅读全帖
c***2
发帖数: 838
10
来自主题: JobHunting版 - Microsoft screening programming problem
int strdis(const char *str, char ch1, char ch2, int n)
{
const char *pf;
const char *p=str;

if(!str)
return 0;

while(*p){
while((*p)&&(*p!=ch1)&&(*p!=ch2)) p++;
if(!(*p)) return 0;

pf=p;
if(*p==ch1){
while(*p&&(*p!=ch2)) p++;
}
else{
while(*p&&(*p!=ch1)) p++;
}
if(!(*p)) return 0;
if(p-pf<=n)
return 1;
//wind back
... 阅读全帖
s*******f
发帖数: 1114
11
using System;
using System.Collections.Generic;
using System.Text;
namespace MSC
{
class Program
{
//“bool F(string s, char ch1, char
ch2, int n)”
//The function determines whether
or not there exists an occurrence of
//ch1 and ch2 separated by a
distance of no more than n in the given
//string s, where s is ascii and
user entered (your function needs
//to work on any input.) The
function must be efficient and
//**optimized** for both space... 阅读全帖
J*******i
发帖数: 2162
12
来自主题: JobHunting版 - 一道amazon题
我的一个解法,有些细节没有完全优化
import java.util.*;
public class StrPermute {
public static void main (String[] args) {
strPermute(args[0]);
}
public static void strPermute (String str) {
char[] ori = str.toCharArray();
boolean[] avail = new boolean[ori.length];
for (int i=0;i avail[i] = true;
char[] result = new char[ori.length];
permute(ori, avail, result, 0);
}
public static void permute (char[] ori, boolean[]... 阅读全帖
Z**********4
发帖数: 528
13
来自主题: JobHunting版 - java没有指针真麻烦
bool isMatch(char *str, const char* pattern) {
while (*pattern)
if (*str++ != *pattern++)
return false;
return true;
}
以上是C code 判断str里面是不是存在pattern
如果改成java的话
private static boolean isMatch (char[] str,char[] pattern)
{
int i=0;
while(i {
if(str[i]!=pattern[i])
return false;
i++;
}
return true;
}
是不是只能这样啊?java不能用指针嘛?还有我只能用i char数组作为参数 这样很不方便啊 我试了pattern.charAt(i)!=... 阅读全帖
g******0
发帖数: 221
14
来自主题: JobHunting版 - 问个 Palindrome 的问题
Start from the front and the back at the same time.
Back always decrease, front can increase or reset to 0.
O(n)
working code attached in c++.
===========================
#include
#include
using namespace std;
char* longestPalindromePrefix(char* str, int len)
{
bool flag = 0;
int front = 0;
int back = len-1;
// Find palindrome
while(front < back)
{
if (str[front] == str[back])
{
flag = 1;
front++;
back--;
}
else
{
fl... 阅读全帖
k***t
发帖数: 276
15
来自主题: JobHunting版 - 收到G家拒信,发面经
我也试一个,in-placed的。先把要删掉的mark成'*'。第二次遍历时再删掉。
#include
// /a/b/./../../c/d => /c/d
void path (char *in) {
char *p, *q;
bool isSlash;
char inv='*';
if (!in || !*in) return;
int i=0;
// parse
p=in; isSlash=false;
while (*p) {
/* first slash */
if (*p=='/') {
if (!isSlash) {
isSlash=true;
} else {
*p=inv;
}
p++; continue;
}
isSlash=false;
... 阅读全帖
f*****y
发帖数: 444
16
来自主题: JobHunting版 - 嵌入式系统软件工程师面经
phone interview with hiring manager & hw engineer - 1 hour
1. brief introduction of company
2. resume questions
3. Difference between i2C and SPI bus? CAN bus?
4. what is size of char, char*, void*, int?
5. What debugger tools do you use? Are you familiar with ICE?
6. Node a and b has resistor r1 and node b has resistor r2 to ground.
Node a have Va, what is Vb? why use this circuit? if exchange r2 to a
capacitor, what circuit is this? can this circuit be implemented by software
and how?
7. how d... 阅读全帖
h*****g
发帖数: 944
17
谢谢大家指点,compile有warning, 执行起来segmentation fault
#include
using namespace std;
void reverse (char *str);
int main(){
char * str = "hello";
reverse(str);
cout< }
void reverse(char *str){
char * end = str;
char tmp;
if(str){
while(*end){
++end;
}
--end;
while(str tmp = *str;
*str++=*end;
*end--=tmp;
}//end while
}
}
s*********3
发帖数: 389
18
来自主题: JobHunting版 - 一道G题
I wrote some Java code afterwards. It seems not very clean. Please comment.
import java.util.*;
//Assumptions:
//1. We can move either up or down or left or right at any point in time,
but not diagonally.
//2. One item in the matrix can not be used twice to compose of the pattern
string.
//3. If different routes lead to the same indexes of matrix items to compose
of the pattern string, display them.
//4. The maximum number of movable steps is (matrix.length - 1) + (matrix[0]
.length - 1) = matri... 阅读全帖
g**********y
发帖数: 14569
19
来自主题: JobHunting版 - 一个老算法题【update】
前天在版上看到打印所有矩阵结合次序(Catalan Numbers)的讨论,最后给出的程序比
较长,我想了一下,既然都是Catalan Numbers, 那么生成Dyck word list的程序应该
可以变形成矩阵结合次序。
CareerCup给出的Dyck word list程序很简洁,我就试着映射了一下:
先推‘A’进栈
对应Dyck word (比如XXXYYY), 遇到X, push nextChar 进栈;
遇到Y, 如果pop()出两个,结合后推进栈
==============================================================
以上是写完后在路上刚悟到的,这个映射应该还算简单。如果不用映射,谁能给个更简洁的解法?
附Java code ==>
public void generate(int count) {
print(count, count, new char[2*count], 0);
}

public void print(int l, int r, char[] s... 阅读全帖
s********x
发帖数: 914
20
来自主题: JobHunting版 - Microsoft interview question
// input I AM Engineer
// output Engineer AM I
public static char[] reverseWordinString(char[] string){
char[] result = new char[string.length];
int k = 0;
for (int i = string.length-1; i >=0 ; ){
if (!isWord(string[i])) {
int j = i;
while (j>=0&&!isWord(string[j])) j-- ;
if (j==0 && !isWord(string[0]))
result[k++] = string[0];
for (int t = j + 1 ; t <= i ; t ++)
... 阅读全帖
S**I
发帖数: 15689
21
来自主题: JobHunting版 - Microsoft interview question
#include
#include
void reverseStr(char str[], int begin, int end){

char temp;

while(end > begin){
temp = str[begin];
str[begin++] = str[end];
str[end--] = temp;
}
}
void reverseWord(char str[]){

int begin = 0, end = 0, length = (int) strlen(str) - 1;

reverseStr(str, begin, length);

while(end < length){

if(str[end] != ' '){

begin = end;

while(end... 阅读全帖
m*********2
发帖数: 701
22
来自主题: JobHunting版 - 问一道关于reverse a C-string的问题
我考试时是这样写的. 不太好, 应该是比那个强吧
char *strrev(char *s)
{
int length =0;
while (*s++)length++;
char* ptr = s;
char* result = (char *)malloc(length+1);

int i=0;
for (; i < length; i++;)
*(result+i) = *--ptr;
*(result + i + 1) = '\0';
return result;
}
p****e
发帖数: 37
23
来自主题: JobHunting版 - 两道F电面题
1. remove duplicated characters,keep original order
"abcdace" -> "abcde"
"aaaab" -> "ab"
prototype:
char * remove_dup(char * s)
2. implement regular expression match.
we only need to support "." and "*" ("." means any character, and "*" means
repeat previous char 0 or any times), and we need to match the whole input
for example,
match("aa","a") -> false
match("aa","aa") -> true
match("aa", "a*") -> true
match("aa", ".*") -> true
match("aab", "c*a*b") ->true
the prototype is:
bool is_match(const ... 阅读全帖
p****e
发帖数: 37
24
来自主题: JobHunting版 - 两道F电面题
1. remove duplicated characters,keep original order
"abcdace" -> "abcde"
"aaaab" -> "ab"
prototype:
char * remove_dup(char * s)
2. implement regular expression match.
we only need to support "." and "*" ("." means any character, and "*" means
repeat previous char 0 or any times), and we need to match the whole input
for example,
match("aa","a") -> false
match("aa","aa") -> true
match("aa", "a*") -> true
match("aa", ".*") -> true
match("aab", "c*a*b") ->true
the prototype is:
bool is_match(const ... 阅读全帖
s**********e
发帖数: 326
25
我来贴个general的code
void diagnalPattern(char* str, int rowNum){
int charNum = 0;
for(int i = 0; i < strlen(str); i++){
if(isValidChar(str[i])){
charNum++;
}
}
int colNum = (charNum + rowNum - 1) / rowNum;
char** arr;
arr = new char*[rowNum];
for(int i = 0; i < rowNum; i++)
arr[i] = new char[colNum];
for(int i = 0 ; i < rowNum; i++)
for(int j = 0; j < colNum; j++)
arr[i][j] = ' ';
int curPos = 0;
... 阅读全帖
a***r
发帖数: 93
26
这题如果用DP来做,哪位给分析一下什么是subproblem?
【 以下文字转载自 Programming 讨论区 】
发信人: minisand (老婆是A+海博), 信区: Programming
标 题: 请教一个字符串比较排序的问题
发信站: BBS 未名空间站 (Mon Nov 9 16:35:46 2009, 美东)
之前有人贴出了常见的那个求Maximum repetitive substring的代码,如下:
void MaxDuplicatedSubstring(char *input, char *result)
{
int length = strlen(input);
char **substrings = new char**[length];
for (int i=0; i < length; i++)
substrings[i] = input + i;
qsort(substrings, length, sizeof(char*), (int (*)(const void*, const void*
))strcmp);
... 阅读全帖
s*******f
发帖数: 1114
27
来自主题: JobHunting版 - one facebook software problem
//Implement a function string balanceParanthesis(string s); which given a
//string s consisting of some parenthesis returns a string s1 in which
//parenthesis are balanced and differences between s and s1 are minimum.
//Eg - "(ab(xy)u)2)" -> "(ab(xy)u)2"
//")))(((" -> ""
void DelBrackets(char *str){
if (!str)
return;
deque sc;
deque sp;
char *p = str;
while (*p){
if (*p == '('){
sc.push_back('(');
sp.push_back(p);
}... 阅读全帖
s*******y
发帖数: 105
28
来自主题: JobHunting版 - Exposed上一道string permutation的题
求一个string的所有的permutation. C code如下:
int permutations(char *str)
{
int length, i, *used;
char *out;
length = strlen(str);
out = (char *)malloc(length+1);
if(!out)
return 0;
out[length] = '\0';
used = (int*)malloc(sizeof(int)*length);
if(!used)
return 0;
for(i=0;i used[i]=0;
DoPermute(str, out, used, length, 0);
free(out);
free(used);
return 1;
}
void DoPermute(char *str, char* out, int* used, int length, int recursLev)
{
int i;
if(recursLev==l... 阅读全帖
w****x
发帖数: 2483
29
来自主题: JobHunting版 - 大家看看我写的这个itoa有没有bug
const char* myitoa(int num, char str[])
{
assert(a);
char* pIterBeg = str;
if (num < 0)
{
num = -num;
*pIterBeg++ = '-';
}
//use long not short to avoid INT_MIN overflow
unsigned int numshort = num;
char* pIter = pIterBeg;
while (true)
{
*pIter++ = numshort%10 + '0';
numshort = numshort/10;
if (numshort == 0) break;
}
*pIter = 0;
int nLen = strlen(pIterBeg);
assert(nLen > 0);
char* pIterEnd = ... 阅读全帖
w****x
发帖数: 2483
30
来自主题: JobHunting版 - 大家看看我写的这个itoa有没有bug

const char* myitoa(int num, char str[])
{
char* pIterBeg = str;
if (num < 0)
{
num = -num;
*pIterBeg++ = '-';
}
unsigned int numshort = num; //avoid INT_MIN overflow
char* pIter = pIterBeg;
do
{
*pIter++ = numshort%10 + '0';
numshort = numshort/10;
}while (numshort != 0);
*pIter = 0;
char* pIterEnd = pIter - 1;
while (pIterEnd > pIterBeg)
swap(*pIterBeg++, *pIterEnd--);
return str;
}
谢谢提醒, 修改版本
c*****e
发帖数: 737
31
来自主题: JobHunting版 - 最新某公司onsite面试题
1,
int a[] = {1,2,3,4,5};
int *p2 = &a + 1;
printf("%d, %d", *(a+1), *(p - 1));
说出结果
2, const char* p;
char* const p;
char const* p;
解释
第三题太长了记不得
4, 如果你在linux下要编译一个项目,但磁盘已经满了,于是你mount了一个win的fs到
你home下,但有个问题,不能soft link,你如何build?
5,用C(不是C++)实现从/etc/resolve.conf下读取所有ip地址,返回char ** dns;
e.g.
mitbbs.com 74.125.78.121
mitbbs.ca 78.45.147.145
...
返回的就是所有ip地址的string array(所以是char **)
p*****2
发帖数: 21240
32
来自主题: JobHunting版 - 罗马数字转换成十进制
import java.io.*;
import java.util.*;
public class Roman
{
public static void main(String[] args)
{
new Roman().run();
}
PrintWriter out = null;
void run()
{
Scanner in = new Scanner(System.in);
out = new PrintWriter(System.out);
String s = in.next();
out.println(romanToInt(s));
out.close();
}
public String intToRoman(int num)
{
StringBuffer sb = new StringBuffer();
sb.append(Convert(num, 1000, ne... 阅读全帖
w****x
发帖数: 2483
33
来自主题: JobHunting版 - 昨天的F家店面
int read4096(FILE* pf, char* pBuf);
char buf[4096];
int nLen = 0;
char* readline(char* szMem, FILE* pf)
{
assert(szMem);
bool bRet = false;
char* pWrite = szMem;
while(true);
{
int i = 0;
for (; i < nLen; i++)
if (buf[i] == 0 || buf[i] == '\n')
{
bRet = true;
break;
}
int nMove = i+1;
if (!bRet)
nMove = i;
memcpy(pWrite, buf, nMove);
... 阅读全帖
w****x
发帖数: 2483
34
来自主题: JobHunting版 - 昨天的F家店面

..
为什么要逼我用stl...
int read4096(FILE* pf, char* pBuf);
char buf[4096];
int nLen = 0;
char* readline(FILE* pf)
{
std::string strRet;
bool bFound = false;
while(true);
{
int i = 0;
for (; i < nLen; i++)
{
if (buf[i] == 0 || buf[i] == '\n')
break;
strRet.append(buf[i]);
}
if (i == nLen)
nLen = 0;
else
{
nLen -= i+1;
memcpy(buf, buf+i+1, nLen);
... 阅读全帖
a**U
发帖数: 115
35
来自主题: JobHunting版 - 一个C++面试题
delete p; 问题在那里?
是不是array中某个char是'\0', 比如说p[3]='\0',后面的就没有删掉?
还是说delete p就只是删了第一个char?
char* p = (char*)malloc(10);
如果用delete(p)是不是只是deallocate第一个char?
n*******w
发帖数: 687
36
来自主题: JobHunting版 - F家面经
1. regex
test过了,要源码的话站内吧。
bool regex(char* str, char* pattern)
if(!str && !pattern) return true;
if(!str || !pattern) retrun false;
if(pattern+1 && *(pattern+1) == '-' && pattern+2) //handle a-z
return *str >= *pattern && *str <= *(pattern+2) && regex(str+1,
pattern+3);
if(pattern+1 && *(pattern+1) == '+')
if(*pattern == '.') //handle .+
bool tmp = false;
char* iter = pattern;
while(iter) //iterater over all possible repeated t... 阅读全帖
p********s
发帖数: 37
37
来自主题: JobHunting版 - 那个24 game given 4 number用= - × /的题
写了个超级傻的,各种没效率,您别笑话囧
int pl(int a, int b) { return a + b; }
int mi(int a, int b) { return a - b; }
int ti(int a, int b) { return a * b; }
int di(int a, int b) { return (b && !(a % b)) ? (a / b) : -12345 ; }
int (*op[4])(int a, int b) = {&pl, &mi, &ti, &di};
const char *name[4] = {"+", "-", "*", "/"};
char result[128] = {0};
bool tryit(int nums[], char* res)
{
char result[128];
for(int i = 0; i < 4; i++)
for(int j = 0; j < 4; j++)
for(int k = 0; k < 4; k++)
if ((*op[k])((*op[j])((*op... 阅读全帖
p********s
发帖数: 37
38
来自主题: JobHunting版 - 那个24 game given 4 number用= - × /的题
写了个超级傻的,各种没效率,您别笑话囧
int pl(int a, int b) { return a + b; }
int mi(int a, int b) { return a - b; }
int ti(int a, int b) { return a * b; }
int di(int a, int b) { return (b && !(a % b)) ? (a / b) : -12345 ; }
int (*op[4])(int a, int b) = {&pl, &mi, &ti, &di};
const char *name[4] = {"+", "-", "*", "/"};
char result[128] = {0};
bool tryit(int nums[], char* res)
{
char result[128];
for(int i = 0; i < 4; i++)
for(int j = 0; j < 4; j++)
for(int k = 0; k < 4; k++)
if ((*op[k])((*op[j])((*op... 阅读全帖
g****y
发帖数: 240
39
来自主题: JobHunting版 - interleaved string
Edit: 好像不对,还是更复杂的情况。
想了一个O(n)的解法。请帮忙看一下对不对。
if A and B have no duplicate char: easy problem. just traverse C. increase A
's
index if A's char matches or increase B's index if B's char matches.
if A and B have duplicate chars, we assume A[i, j] == B[m, n].
when we traverse C and in the position where C[k] == A[i] == B[m], we have
two ways to go: increase A's index or increase B's index. in this kind of
situation, we will always select to increase A's index.
if we are lucky, A is the right way to ... 阅读全帖
g*******n
发帖数: 214
40
来自主题: JobHunting版 - G电面一题
如果不用recursion的话代码太长是不是面试的时候不能用?
public ArrayList numString2Char(String num) {
//map to store all the previous possibilities
HashMap> map = new HashMap ArrayList>();
int[] numbers = new int[num.length()];
for (int i = 0; i < num.length(); i++) {
numbers[i] = Integer.parseInt(num.charAt(i) + "");
}
if(numbers[0]==0) return null;
ArrayList tempList;
... 阅读全帖
f**********t
发帖数: 1001
41
来自主题: JobHunting版 - 再论设计里面的Card class
我想实现Card class里面的输入牌的名字
然后代码如下:
char* Card::NameOf() {
static char szName[20];
static char *Numbers[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "
10", "Jack", "Queen", "King"};
static char *Suits[] = {"Clubs", "Spades", "Hearts", "Diamonds"};
if (GetCardinal() < 13) {
strcat(szName, Numbers[GetCardinal()]);
}
strcat(szName, " of");
if (GetSuit() <= 4) {
strcat(szName, Suits[GetSuit() - 1]);
}
return szName;
}
reference在这里:http://msdn.micr... 阅读全帖
Q*******e
发帖数: 939
42
//caller has to free memory allocated
char *string_reverse2(const char *string)
{
int len;
char * str = string;
char * res;
len = 0;
while (*str++) len++;
str--;
res = (char*) malloc(len + 1);
//sanity check here
while (len > 0) {
*res++ = *str--;
len--;
}
*res = '\0';
return res;
}
M******l
发帖数: 479
43
来自主题: JobHunting版 - BB家面经
1.给一个char数组和一个特殊char,要求把数组排序,小于那个特殊char的放在大于特
殊char的左边。回答了quick sort的第一步,不满意,闲不够快,然后改进成两头都标
记减少swap,发现大于特殊char的再从右边找一个小于的交换,总算满意了。感觉面试
的那个人似乎不太明白quick sort……
2. 给报纸上的那种填字游戏标记1,2,3序号,一个单词必须由两个以上字母组成,中
间有些cell是空的。这个题我纠结了很久,没弄清楚具体要求,而且被第一题那个人有
点吓到了,自己又不怎么玩填字游戏~~
3.然后问了多线程的问题,回答java里面每个object都有一个锁,所以不常写sync的方
法。
居然把我跟别的刚毕业新生算成是一样的了,好歹我也两年工作经验啊,虽然是java…
w****x
发帖数: 2483
44
int mul(const char*& p);
int num(const char*& p);
int Add(const char*& p)
{
int res = mul(p);
while (*p == '+' || *p == '-')
{
if (*p == '+')
res += mul(++p);
else
res -= mul(++p);
}
return res;
}
int mul(const char*& p)
{
int res = num(p);
while (*p == '*' || *p == '/')
{
if (*p == '*')
res *= num(++p);
else
res /= num(++p);
}
return res;
}
int num(const char*& p)
{
bool b... 阅读全帖
w****x
发帖数: 2483
45
int mul(const char*& p);
int num(const char*& p);
int Add(const char*& p)
{
int res = mul(p);
while (*p == '+' || *p == '-')
{
if (*p == '+')
res += mul(++p);
else
res -= mul(++p);
}
return res;
}
int mul(const char*& p)
{
int res = num(p);
while (*p == '*' || *p == '/')
{
if (*p == '*')
res *= num(++p);
else
res /= num(++p);
}
return res;
}
int num(const char*& p)
{
bool b... 阅读全帖
c********t
发帖数: 5706
46
来自主题: JobHunting版 - leetcode出了新题word ladder
多谢!
第一题最后发现用 char array 比 StringBuilder还快
第二题又超时了,再求帮助!
用的是双queue解法,感觉比你和wwwyhs说的hashmap>用空间
更少,时间也应该更少,为啥又超呢?(唉,我为什么又说又)
public ArrayList> findLadders(String start, String end,
HashSet dict) {
// Start typing your Java solution below
// DO NOT write main() function
ArrayList> ret = new ArrayList>(
);

int curr=1, next=0, count=1, n=start.length(), length=Integer.MAX_
VALUE... 阅读全帖
c********t
发帖数: 5706
47
来自主题: JobHunting版 - leetcode出了新题word ladder
多谢!
第一题最后发现用 char array 比 StringBuilder还快
第二题又超时了,再求帮助!
用的是双queue解法,感觉比你和wwwyhs说的hashmap>用空间
更少,时间也应该更少,为啥又超呢?(唉,我为什么又说又)
public ArrayList> findLadders(String start, String end,
HashSet dict) {
// Start typing your Java solution below
// DO NOT write main() function
ArrayList> ret = new ArrayList>(
);

int curr=1, next=0, count=1, n=start.length(), length=Integer.MAX_
VALUE... 阅读全帖
b******n
发帖数: 823
48
来自主题: JobHunting版 - 发一个fb面经
店面:
Input: Sorted array, int k, Output: All pairs of indices (i,j) such that A[
j] - A[i] = k
这个很简单,俩指针了事,然后问如果有dup的情况怎么办。
onsite 4轮,都是常规题:
1. 问research, 怎么group anagrams together
2. most freq char in str,很简单,ct[256]搞定,
然后问了一堆扩展和特殊情况,这人一看就很geek
what if str is empty, what to return
what if just to find most freq alphabetic char
如果有一个upper case char 和一个lower case char出现相同多次,你的程序
output哪一个
how to output all most freq chars instead of just one
what if utf8
3. sorted array to bst
... 阅读全帖
w********g
发帖数: 106
49
知识题:
C++和Java的区别
JVM怎么工作
其余的忘记了,也都是基本概念。
编程题:
大数加法
char* add(const char*a, const char *b){ }
原以为一面就会挂,结果面试官发善心让我过了。二面的面试官可能有事,过了半小时
才打来电话。面试官是国人大哥,英语没口音,但是他念我的名字按照中国人顺序念。
因为电话迟了半小时,所以整个面试只有半小时,所以只有一道编程题。题目很简单,
但我做的很差,因为可恨我很久不用C编程了,把strlen、strcpy都忘记了。我写C++的
string.length(),结果他说只能写C的。我说我忘了,其实我记的,但是一着急就写错
了,NND一个参数的基础函数我都能写错。
我写了一句
char *result = (char*)malloc( max( strlen(a), strlen(b) ) +2 );
我边写他就边找bug,我一行还没写完他就指出我的错误。看来以后要养成一遍成的习
惯。由此我也知道这次挂了,因为对方显然要求一遍就过。
这位面试官思路很活跃很快,从来不等我把话说完或者把某一块代码写完。另外比如我... 阅读全帖
J****3
发帖数: 427
50
char *compress(char* str){
int rlen;
int len = strlen(str);
char* dest = (char*)malloc(sizeof(char)*(2*len+1));
int j = 0;
for(int i = 0; i < len; i++){
dest[j++] = str[i];
rlen = 1;
while(i+1 < len && str[i] == str[i+1]){
rlen++;
i++;
}
dest[j++] = rlen+'0';
}
dest[j] = '\0';
return dest;
}
O(n) 但是不是inplace的 你看看行不
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)