jiangok2006
BAN USER- 0of 0 votes
AnswersGiven N matrix production (A1*A2*A3...*AN), different matrix can have different dimensions but they satisfy the production requirement. For example, A1 is 2x3, then A2 can be 3x4 but not 5x2. When a 3x2 matrix products a 2x4 matrix, the total number of number production required is 24. How to reduce the total number of number production when calculating (A1*A2*A3...*AN)?
- jiangok2006 in United States| Report Duplicate | Flag | PURGE
- 0of 0 votes
AnswersThere are 4 types of coins (25 cent, 10 cent, 5 cent and 1 cent). Given a number, return the minimum number of coins whose sum equals to this number. What about the 4 types of coins changes to (25, 10, 6, 1)? Write code.
- jiangok2006 in United States| Report Duplicate | Flag | PURGE
- 0of 0 votes
AnswersGiven N matrix production (A1*A2*A3...*AN), different matrix can have different dimensions but they satisfy the production requirement. For example, A1 is 2x3, then A2 can be 3x4 but not 5x2. When a 3x2 matrix products a 2x4 matrix, the total number of number production required is 24. How to reduce the total number of number production when calculating (A1*A2*A3...*AN)?
- jiangok2006 in United States| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
Answersdesign a data structure for caching the result of "int getSmallestBiggerPrime(int)" so that the client side can reduce the trips to the server as much as possible. There are some examples in format of input->output: 1->1, 2->2, 3->3, 4->5, 5->5, 6->7, 7->7, 8->11, 9->11...
- jiangok2006 in United States
The interviewer did not say whether to use Least Recently Used (LRU) or Most Recently Used (MRU). But he gave a requirement using an example, suppose the user inputs 6 and gets 7 last time, the next time when he inputs 7, there should be no server trip to get 7 as the result.| Report Duplicate | Flag | PURGE
Data Structures - 0of 0 votes
AnswersUse iteration to find the common ancestor of two nodes on a BST.
- jiangok2006 in United States| Report Duplicate | Flag | PURGE
Coding - 0of 0 votes
AnswersGiven a line, adjust this line to the page width.
- jiangok2006 in United States
For example, given "Dog is cute" (length of chars is 11) and the page width is 15, adjust the line to "Dog is cute". The extra spaces should be distributed as much even as possible. Assume there is no space before the first word or after the last word.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 1of 1 vote
AnswersGiven preorder traversal array of a BST, recontruct the BST.
- jiangok2006 in United States| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 0of 2 votes
AnswersGiven API:
- jiangok2006 in United States
int Read4096(char* buf);
It reads data from a file and records the position so that the next time when it is called it read the next 4k chars (or the rest of the file, whichever is smaller) from the file.
The return is the number of chars read.
Todo: Use above API to Implement API
"int Read(char* buf, int n)" which reads any number of chars from the file.| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Coding - 0of 0 votes
AnswersInput a string and a pattern having . and *
- jiangok2006
Output: whether the string fully matches the pattern
. match any char, * means matching 0 or more times.
Example:
input "a", "." => match
input "abc", ".*" => match
input "abcd", "a.*d" => match| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersInput:
- jiangok2006
Either an object array having integer, string and boolean, like
{"abc", "ab,c", 10, true, false}
Or a hash table like
{"a1":"abc","t":true,"e":123}
Output:
If object array, output
"abc"
10
true
If hash, output
"a1":"abc"
"t" : true
"e" : 123| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm
like
- jiangok2006 September 10, 2012tag
- jiangok2006 September 04, 2012tag
- jiangok2006 September 04, 2012tag
- jiangok2006 September 03, 2012tag
- jiangok2006 September 03, 2012Node* f(Node* r, int *n)
{
if(*n<0 || r==null)
return null;
if(*n==0)
return r;
Node* t = f(r->left, n);
if(t)
return t;
if(*n==0)
return r;
*n = (*n)-1;
return f(r->right, n);
}
// recursive version
int f(Node* r)
{
if(r==null)
return 0;
int ld = f(r->left);
int rd = f(r->right);
if(ld==0 || rd==0)
return 0;
return 1+min(ld, rd);
}
// iteration version using BFS
int f(Node* r)
{
if(r==null)
return 0;
Queue* q = new Queue();
q->enque(r);
int c0=1; // expected current level's node count.
int c1=2; // expected next level's node count
int l = 0; // max depth of complete tree
while(!q->empty())
{
Node* t = q->deque();
c0--;
if(t->left)
{
q->enque(t->left);
c1--;
}
if(t->right)
{
q->enque(t->right);
c1--;
}
if(c0==0)
{
if(c1==0)
{
// complete tree level found, increase depth l and update expected node counts.
l++;
c0=c1;
c1=c1<<1;
}
else
{
// incomplete tree level found
break;
}
}
}
delete q;
return l;
}
like this greedy algo. However, there is no need for binary search in the second step. The algorithm has ensured the new pair's min can ONLY be less then the last element in the array. So you only need to compare its y with the last element in the existing array. So the 2nd step is O(n) instead of O(nlgn).
- jiangok2006 August 31, 2012float StayLiveProb(int x, int y, int steps)
{
if(0<=x && x<M && 0<=y && y<N)
{
if(steps>0)
{
return 0.25*(StayLiveProb(x-1, y, steps-1) + StayLiveProb(x,y-1,steps-1) + StayLiveProb(x+1, y, steps-1) + StayLiveProb(x, y+1, steps-1));
}
return 1;
}
return 0;
}
float DeadProb(int x, int y, int steps)
{
return 1-StayLiveProb(x, y, steps);
}
//O(n2), handling the case a and b haves common chars.
bool IsInterleave(char* a, char* b, char* c)
{
if(!*c)
return !*a && !*b;
return ((*a == *c) && IsInterleave(a+1, b, c+1)) ||
((*b == *c) && IsInterleave(a, b+1, c+1));
}
// in-place, O(n2) for the second step.
void f(int* arr)
{
// step 1: switch positive with negative
int 1stNeg, headNeg;
//1stNeg: the 1st negative in original arr.
//headNeg: the 1st negative in current arr.
1stNeg = headNeg = -1;
for(int i=0;i<strlen(arr);++i)
{
if(arr[i]<0)
{
if(1stNeg<-1)
{
1stNeg = i;
}
if(headNeg < -1)
{
headNeg = i;
}
}
else
{
if(headNeg>-1)
{
swap(arr[headNeg], arr[i]);
}
if(headNeg == 1stNeg)
{
1stNeg = i;
}
headNeg++;
}
}
//step 2: shift the out of order negative numbers to make them in order.
//O(n2) time complexity.
if(headNeg != 1stNeg)
{
for(int i=1stNeg; i<strlen(arr); ++i)
{
for(int j=1stNeg; j>headNeg; j--)
{
swap(arr[j], arr[j-1]);
}
headNeg++;
}
}
}
like
- jiangok2006 August 27, 2012For input:
int arr1[5] = { 3, 5, 2, 5, 2}
int arr2[5] = { 2, 3, 5, 5, 2}
They are the same if:
1) XOR all numbers in arr1 and arr2 is 0
2) Sum of all differences between arr1 and arr2 are 0. For example, 1+2+(-3)+0+0=0
// C#
// use hashtable to get the occurrences of chars.
// only search repeating strings using the chars having >1 occurrences.
bool FindRepeatingString(string s)
{
if(string.IsEmptyOrNull(s) || s.length < 2)
return false;
HashTable<char, List<int>> ocTable = new HashTable<char, List<int>>();
// construct occurrence hashtable.
for(int i=0;i<s.length;++i)
{
if(!ocTable.ContainKey(s[i]))
{
List<int> ocList = new List<int>();
ocList.Add(i);
ocTable.Add(s[i],ocList);
}
else
{
ocTable[s[i]].Add(i);
}
}
// for each char having >1 occurrences, check whether they are the starting points of repeating strings.
foreach(char c in ocTable.Keys)
{
if(ocTable[c].Count>1)
{
if(FindRecur(s, c, ocTable[c],0) == true)
return true;
}
}
return false;
}
// recursion function to check whether the occurrences in ocList point to the repeating strings.
bool FindRecur(string s, char c, List<int> ocList, int cur)
{
if(cur>ocList.Count-2)
return false;
for(int i=cur+1; i<ocList.Count; ++i)
{
bool match = true;
int st = ocList[cur];
int end = ocList[i];
int n = end-st;
for(int j=0; j<n; ++j)
{
if(s[st+j] != s[end+j])
{
match = false;
break;
}
}
if(match)
return true;
}
return FindRur(s, c, ocList, cur+1);
}
// find the next biggest node in BST
Node* FindNextBiggest(Node* r, Node* cur)
{
if(r == null || cur == null)
return null;
// if cur is the root, return the min on the right child.
if (cur->value == r->value)
{
return FindMin(r->right);
}
else if(cur->value < r->value)
{
// if cur is on the left child, try to get the next biggest on the left child.
// if left child does not have the next biggest, return root.
Node *bigger = FindNextBiggest(r->left, cur);
return bigger == null ? r : bigger;
}
else
{
// if cur is on the right child, get the next biggest on the right child.
// return null if cur points to the maximum in the tree.
return FindNextBiggest(r->right, cur));
}
}
Node* FindMin (Node* r)
{
if(r == null)
return null;
Node* p = r;
while(p->left != null)
p = p->left;
return p;
}
Tag
- jiangok2006 August 21, 2012// main function
bool mainfunc(char* s)
{
return f(s, 0);
}
// recursive function
bool f(char* s, int cur)
{
int target = (strlen(s)+cur)/2;
for(int i=cur+1; i<target; ++i)
{
if(match(s, cur, i))
return true;
}
if(cur<strlen(s)-1 && f(s, cur+1))
return true;
return false;
}
// helper function to match substring from cur to tar (exclusive)
// with that from tar to tar + (tar-cur)
bool match(char* s, int cur, int tar)
{
for(int i=0;i<tar-cur;++i)
{
if(s[cur+i]!=s[tar+i])
return false;
}
return true;
}
@Ashish, this should NOT happen.
- jiangok2006 August 20, 2012// this function prints the most beautiful string using C#.
// A hashtable is constructed to record the positions of each char.
// The hashtable keys are examed from the greatest (e.g. 'z) to the
// smallest (e.g. 'a') one by one against the input string. If this char
// is duplicated, keep the first one that is greater than its next neigbor and
// delete all other occurrences by marking as spaces (do not shift chars so as
// to reduce cost). At last, print the string by ignoring spaces.
//
// Assumption: the input string does not use spaces so that spaces can be used as marker.
// If the input string does not have dup chars, the original string is printed as it is
// already the most beautiful one.
void f(string s)
{
HashTable<char, List<int>> h = new HashTable<char, List<int>>();
//
// construct the hash table using s, recording the positions of each char.
//
for(int i=0;i<s.length;++i)
{
if(!h.Contains(s[i]))
{
List<int> list = new List<int>();
list.Add(i);
h.Add(s[i], list);
}
else
{
h[s[i]].Add(i);
}
}
// sort keys so that we can remove the chars from 'z' to 'a'.
h.Keys.Sort();
for(int i=h.Keys.Count-1; i>-1;i--)
{
char ch = h.Keys[i];
// if this char has >1 occurrences
if(h[ch].Count>1)
{
bool OneKept = false; // is one such char kept from deleting?
for(int j=0;j<h[ch].Count;++j)
{
int idxS = h[ch][j];
int nextNonSpace = idxS+1;
while(nextNonSpace < s.length && s[nextNonSpace] == ' ' )
nextNonSpace++;
if(!OneKept && (nextNonSpace >= s.length || s[idxS] > s[nextNonSpace] || j == h[ch].Count-1))
{
OneKept=true;
}
else
{
// delete other dup chars by marking as space.
// don't shift chars to avoid heavy cost.
s[idxS] = ' ';
}
}
}
}
for(int i=0;i<s.length;++i)
{
if(s[i]!=' ')
{
Console.Write(s[i]+" ");
}
}
}
void mainfunc(int n)
{
char* s = new char[n*2 + 1];
s[n*2] = '\0';
f(n, n, s, 0, 0);
}
void f(int cLeft, int cRight, char* s, int idxS, int leftToMatch)
{
if(cRight == 0)
{
printf("%s\n", s);
return;
}
if(cleft != 0)
{
s[idxS+1]='(';
f(cLeft-1, cRight, s, idxS+1, leftToMatch+1);
}
if(leftToMatch!=0)
{
s[idxS+1] = ')';
f(cLeft, cRight-1,s,idxS+1,leftToMatch-1);
}
}
Good discussion. not coding friendly.
- jiangok2006 August 18, 2012en.wikipedia.org/wiki/Hungarian_algorithm
It is a greedy algorithm.
// DP algorithm:
// W is the minimum coins to sum up to sum (s) given coins (c).
// W(s, c) = min (W(s-ci, c-ci)) + 1;
// using C#
// global var.
// Context has information of current Sum and available coins.
// int is the minimum coin count to satisfy the Context.
// if there is no solution for this context, the context will not be in this hash table.
HashTable<Context, int> T = new HashTable<Context, int>();
class Context
{
public int s;
public HashTable<int, int> coins;
public void Context(int s, int[] arr)
{
coins = new HashTable<int, int>();
foreach(int a in arr)
{
if (coins.ContainKey(a))
{
coins[a].value++;
}
else
{
coins.Add(a, 1);
}
}
this.s = s;
}
public void Context(int s, HashTable<int, int> coins)
{
this.s = s;
//TODO: create new HashTable and copy data from coins.
}
// find all available coins whose values is not greater than the sum.
public List<int> AvailableNotGreater()
{
List<int> t = new List<int>();
foreach(int k in coins.Keys())
{
if(k <= s)
{
t.Add(k);
}
}
return t;
}
// remove a coin from the context.
public void Remove(int z)
{
if(z>s)
throw new ArgumentException();
if(!coins.ContainKey(z))
{
throw new ArgumentException();
}
s-=z;
if(coins[z]==1)
{
coins.Remove(z);
}
else
{
coins[z]--;
}
}
}
// main function for this question.
// return the minimum coins for the sum (s). return INT_MAX if not found.
int mainfunc(int s, int[] arr)
{
Context context = new Context(s, arr);
f(context);
if(T.ContainKey(context)
{
return T[context];
}
else
return INT_MAX;
}
// recursive function using DP
void f(Context context)
{
if(T.ContainKey[context)
{
return;
}
foreach(int z in context.AvailableNotGreaterSet())
{
if (z == s)
{
if(T.ContainKey(context))
{
T[context] = 1;
}
else
{
T.Add(context,1);
}
}
Context contextCopy = new Context(context.s, context.coins);
contextCopy = contextCopy.Remove(z);
f(contextCopy);
if(T.ContainKey(contexCopy))
{
int curMin = T[contextCopy]+1;
if(T.ContainKey(context))
{
if(T[context] > curMin)
T[context] = curMin;
}
else
{
T.Add(context, curMin);
}
}
}
}
good point for word truncating problem. When processing a chunk, see whether this chunk ends with a delimiter(e.g. space, common, period...), if so, handle all words in this chunk; otherwise, handle all words before the last one since it may not be complete and update the file pointer accordingly. Then read the next chunk.
- jiangok2006 August 16, 2012reservoir sampling
- jiangok2006 August 16, 2012search Mersenne twister
- jiangok2006 August 15, 2012check Mersenne twister on wikipedia
- jiangok2006 August 15, 2012check en.wikipedia.org/wiki/Mersenne_twister
- jiangok2006 August 15, 2012agree with Anonymous. It is not random.
- jiangok2006 August 15, 2012tag. O(n) solution is not intuitive.
- jiangok2006 August 15, 2012// using C#.
// some functions' implementation are ignored: print, overloading != for class Node.
class Node
{
public:
int x;
int y;
}
void f(int n)
{
Node a = new Node(0,0);
Node last = new Node(n-1, n-1);
while(a!=last)
{
Traverse1st(a); //print the first stroke of Z
Traverse2nd(a); //print the second stroke of Z
Traverse3rd(a); //print the third stroke of Z
if(a!=last)
{
Traverse4th(a); //print the reverting stroke
}
}
print(a);
}
void Traverse1st(Node a)
{
print(a);
if(a.x<n-1)
{
a.x++;
}
else
{
a.y++;
}
}
void Traverse2nd(Node a)
{
print(a);
while(a.x>0 && a.y<n-1)
{
a.x--;
a.y++;
print(a);
}
}
void Traverse3rd(Node a)
{
print(a);
if(a.y<n-1)
{
a.y++;
}
else
{
a.x++;
}
}
void Traverse4th(Node a)
{
print(a);
while(a.x<n-1 && a.y>0)
{
a.x++;
a.y--;
print(a);
}
}
tag
- jiangok2006 August 14, 2012tag
- jiangok2006 August 14, 2012Another recursion using different function signature.
bool f(char* s, char* p)
{
if(*s=='\0' && *p=='\0')
return true;
if(*s=='\0' && *p=='*')
return f(s, p+1);
if(*s=='\0')
return false;
bool foundStar = false;
char* cur = p;
//handle multiple stars in a row.
while(*cur == '*')
{
cur++;
foundStar = true;
}
//if ending with *, return true.
if(*cur == '\0')
return true;
if(foundStar)
{
return f(s+1, cur-1) || f(s, cur) || f(s+1, cur);
}
else
{
if(*cur==*s)
return f(s+1, cur+1);
else
return false;
}
}
Like
- jiangok2006 August 11, 2012Like
- jiangok2006 August 11, 2012char* Adjust(char* s, int width)
{
//TODO: argument validation
//
//get number of words
//
int cWords = 0; // number of words
bool IsWord = false;
char* p = s; // pointer to s
while(*p != '\0')
{
if(*p==' ')
{
IsWord = false;
}
else
{
if(!IsWord)
{
IsWord = true;
cWords++;
}
}
p++;
}
//
//compute extra space distribution
//
int cExtraSpaces = width - strlen(s);
int dist, remain;
if(cWords > 1)
{
dist = cExtraSpaces/(cWords-1);
remain = cExtraSpaces%(cWords-1);
}
else
{
ASSERT(FALSE);
}
//
//copy and insert spaces.
//
//create buf for new string
char* s2 = new char[width+1];
s2[width]='\0';
p=s;
int idxS2=0; // index to iterate through s2
IsWord = false;
int cWords2 = 0; // word count visited in s
while(*p != '\0')
{
if(*p == ' ')
{
IsWord = false;
}
else
{
if(!IsWord)
{
cWords2++;
IsWord = true;
if (cWords2 > 1)
{
int cSpacesInsert = cExtraSpaces;
if(remain>0)
{
cSpacesInsert++;
remain--;
}
for(int i=0;i<cSpacesInsert;++i)
{
s2[idxS2++]=' ';
}
}
}
}
s2[idxS2++] = *p;
}
return s2;
}
// use C# using BFS and backtrack.
void Convert(string a, string b)
{
//TODO: argument validation
//backtrack table.
HashTable<string, string> B = new HashTable<string, string>();
Queue<string> queue = new Queue<string>();
queue.enque(a);
while(!queue.empty())
{
string t = queue.deque();
if (String.Compare(t, b) == 0)
{
// found the dest string.
PrintPath(B, t, a);
return;
}
// BFS
for(int i=0; i<t.length(); ++i)
{
foreach(char c in "a-z")
{
if (c != t[i])
{
string temp = t;
temp[i] = c;
if(IsValidWord(temp) && !B.ContainKey(temp) && String.Compare(a, temp)!=0)
{
queue.enque(temp);
B[temp] = t;
}
}
}
} // end for
} // end while
}
void PrintPath(HashTable<string, string> B, string t, string a)
{
//TODO: argument validation
if(string.Compare(t, a) == 0)
{
return;
}
Console.Writeline(t);
PrintPath(B, B[t], a);
}
This is a valid solution given that the intermediate strings do not need to be valid words.
- jiangok2006 August 08, 2012//inorder traverse using recursion.
//return list header
//t is the list tail
//r is the tree root
Node* Flat(Node* r, Node ** t)
{
Node *h = null;
// handle left tree, set list header.
if(r->left == null)
{
h = r;
}
else
{
Node *leftTail = null;
h = Flat(r->left, &leftTail);
leftTail->right = r;
}
// handle right tree
if(r->right == null)
{
*t = r;
}
else
{
Node *rightListTail = null;
r->right = Flat (r->right, &rightListTail);
}
// return header
return h;
}
Node* MainFunc(Node* r)
{
if(r==null) return null;
Node* tail=null;
return Flat(r, &tail);
}
sorry to miss that. There is another argument to say how may chars need to be read in Read().
- jiangok2006 July 27, 2012no other api is allowed.
- jiangok2006 July 27, 2012int Read4096(char* buf);
char* g_buf[4096];
int g_idxCur = 0;
int g_idxEnd = -1;
int Read(char* buf, int n)
{
//argument validation
if (n==0) return 0;
int idxbuf = 0;
int cReadFromFile = INT_MAX;
//if more to read, call Read4096
while(idxbuf<n && cReadFromFile>0)
{
int cCh = g_idxEnd - g_idxCur + 1;
if(cCh > 0)
{
int cRead = (n-idxbuf < cCh ) ? n-idxbuf : cCh;
for (int i=0; i<cRead; ++i)
{
buf[idxbuf++]=g_buf[g_idxCur++];
}
if (cReadFromFile<4096)
{
break;
}
}
else
{
cReadFromFile = Read4096(g_buf);
g_idxCur = 0;
g_idxEnd = cReadFromFile-1;
}
}
return idxbuf;
}
Node* f(Node* h)
{
if (h==null) return null;
Hash<int, int> *ht = new Hash<int, int>();
Node *hp = h;
Node *nh = null;
Node *nt = null;
while (hp!=null)
{
Node *n = new Node(hp->value);
if (nh == null)
{
nh = nt = n;
}
else
{
nt->next = n;
nt = nt->next;
}
ht.Add(hp, n);
hp = hp->next;
};
hp = h;
while (hp != null)
{
if (hp->random == null)
{
ht[hp]->random = null;
}
else
{
ht[hp]->random = ht[hp->random];
}
hp = hp->next;
}
delete ht;
return nh;
}
// a is the array
// n is the size of the array
void f(int* a, int n)
{
if(n<0) return;
int zeroSt = -1; // point to the first 0 element
for(int i=0;i<n;++i)
{
if(a[i]!=0)
{
if(zeroSt != -1)
{
a[zeroSt++]=a[i];
a[i]=0;
}
}
else
{
if(zeroSt == -1)
zeroSt = i;
}
}
}
The brute force is O(n3). This divide-conquer algorithm must be at least better than that. Other idea?
- jiangok2006 July 22, 2012use recersion similar to binary search. In this case, every recursion excludes 1/8 the search space. What's the complexity?
bool mf(int A[N][N][N], int v)
{
return f(A, 0, N-1, 0, N-1, 0, N-1, v);
}
bool f(int A[N][N][N], int xi, int xj, int yi, int yj, int zi, int zj, int v)
{
if(xi>xj || yi>yj || zi>zj)
return false;
int mx = (xi+xj)/2;
int my = (yi+yj)/2;
int mz = (zi+zj)/2;
if(v>A[mx][my][mz])
{
return f(A, xi, xj, yi, yj, mz, zj) ||
f(A, xi, xj, my, yj, zi, mz) ||
f(A, mx, xj, yi, my, zi, mz);
}
else
{
return f(A, xi, xj, yi, yj, zi, mz) ||
f(A, xi, xj, yi, ym, mz, zj) ||
f(A, xi, mx, ym, yj, mz, zj);
}
}
O(n2)
- jiangok2006 July 21, 2012use recursion. When a * is found and it is not the ending char in the pattern, find each occurrence of the next non-* char of the pattern in the text, call recursion for the substring in the text starting from each occurrence. Return true if any of the recursion is true.
bool mainfunc(char *t, int tlen, char *p, int plen)
{
return f(t, 0, tlen-1, p, 0, plen-1);
}
// recursion function
bool f(char *t, int tst, int tend, char *p, int pst, int pend)
{
if(tst>tend || pst>pend)
return false;
int ti, pi; //ti:index of t; pi:index of p
ti=tst;
pi=pst;
bool foundStar = false; // differentiate match chars w/wo *
while(ti<=tend && pi<=pend)
{
while(p[pi]=='*')
{
pi++;
foundStar=true;
}
if(pi>pend)
return true; // the last char is * in pattern
if(foundStar)
{
// match with each occurrence of p[next], return if anyone is true
for(int i=ti;i<=tend;++i)
{
if(t[i]==p[pi] && f(t,i+1,tend,p,pi+1,pend)==true)
{
return true;
}
}
return false; //none of them return true.
}
if(t[ti]!=p[pi])
return false;
ti++;
pi++;
}
if(ti<=tend || pi<=pend)
return false;
return true;
}
- jiangok2006 September 10, 2012