由买买提看人间百态

topics

全部话题 - 话题: pslow
(共0页)
f****g
发帖数: 313
1
来自主题: JobHunting版 - A simple interview question
The following is my code :S
#include
#include
#include
#define MAXLEN 5
char* countCharInStr(const char* s,
unsigned int len)
{
char *pFast, *pSlow;
unsigned char num[MAXLEN] = {0};
unsigned int count = 0;
unsigned int resC = 0;

if( 0 == len || NULL == s)
{
return NULL;
}

char *res = (char*)malloc(sizeof(char)*len);
if( NULL == res)
{
return NULL;
}

pSlow = s;
pFa... 阅读全帖
n****t
发帖数: 241
2
来自主题: JobHunting版 - Google校园面试题
我看到貌似正确的一个解法,加了很多限制条件。。。
面试题之二叉搜索树的中位数 收藏
这个问题不算是很常见的问题,基本上在中文的论坛社区没有看到过,遇见这个是因为
偶尔在http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi 上面注册了账号而看到的,题目如下:
Given a BST (Binary search Tree) how will you find median in that?
Constraints:
* No extra memory.
* Function should be reentrant (No static, global variables allowed.)
* Median for even no of nodes will be the average of 2 middle elements and
for odd no of terms will be middle element only.
* Algorithm should be efficient in terms of comple... 阅读全帖
w*****1
发帖数: 15
3
来自主题: Programming版 - A string replacement problem from leetcode
void my_replace(char *str, const char *pattern) {
if (str == NULL || pattern == NULL) return;
char *pSlow = str, *pFast = str;
int pLen = strlen(pattern);
while (*pFast != '\0') {
bool matched = false;
while (isMatch(pFast, pattern)) {
matched = true;
pFast += pLen;
}
if (matched)
*pSlow++ = 'X';
// tricky case to handle here:
// pFast might be pointing to '\0',
// and you don't want to increment past it
if (*pFast != '\0')
*pSlow++... 阅读全帖
w*****1
发帖数: 15
4
来自主题: Programming版 - A string replacement problem from leetcode
一个奇怪的现象。下面的code来自 http://leetcode.com/2010/11/microsoft-string-replacement-problem.html
我试了VS2010, VS2012. All get Access violation error on
if (matched)
*pSlow++ = 'X'; // <----error here
First-chance exception at 0x00AD14A3 in test.exe: 0xC0000005: Access
violation writing location 0x00AD586C.
读code和用debugger都看不出问题。 请哪位高人火眼金睛指点一下
#include
#include
#include
bool isMatch(char *str, const char* pattern) {
while (*pattern)
if (*str++ != *pattern++)
... 阅读全帖
(共0页)