class Solution {
public:
bool isMatch(string s, string p) {
return isMatch(s,p,0,0);
}
bool isMatch(string& s, string& p, int ss, int ps)
{
if( (p.empty() && s.empty())  (ps == p.length() && ss == s.length()) )
return true;
if(ps > p.length()  ss > s.length())
return false;
if(ps+1 < p.length() && p[ps+1] == '*')
{
if(isMatch(s,p,ss,ps+2))
return true;
else
{
p.insert(p.begin()+ps, p[ps]);
return isMatch(s,p,ss,ps);
}
}
else if(p[ps] == '.')
return isMatch(s,p,ss+1,ps+1);
else
return s[ss] == p[ps] && isMatch(s,p,ss+1,ps+1);
}
};
nr1286
@nr1286
Posts made by nr1286

can someone explain why my code isnt working cant really figure it out :(

Please Help Understand
can someone explain why the 4 isnt after the 3??
Given 1>4>3>2>5>2 and x = 3, return 1>2>2>4>3>5.

Is memoization possible here
is there a way to use some sort of memoization here (Thoughts/ Ideas)

RE: Given an integer array shuffle the elements in the array such that no two elements are in same place.
would it be possible to create a map of original index and value;
then use backtracking push a number at pos .. except for the value denoted in the map;
or something like that??

RE: Balanced Smileys
can some one explain this in more detail would it be more of a dp programming like integer break??? if we need to analyze whether a smiley is counted as a smiley or close paren

Space and Runtime Complexity
for all of the trie solutions where they use a vector of trienodes of size 26
can someone explain the space and runtime complexity. especially of the search method dealing with the case of a . or all .
Best,
Nick

I Think Leetcode is Buggy
it says my code past all test case as well as memory limit exceed I dont understand can someone check this.
public: int numSquares(int n) { vector<int> v; for(int i= 1; i<=n; i++) { if(i*i == n) return 1; else if(i*i < n) v.push_back(i*i); else break; } queue<pair<int,int>> q; for(int& i: v) q.push(make_pair(i,1)); while(!q.empty()) { auto node = q.front(); q.pop(); if(node.first == n) return node.second; if(node.first < n) { for(int&i : v) { if(node.first+i == n) return node.second+1; q.push(make_pair(node.first+i,node.second+1)); } } } return 1; } };

Is this possible to do using logarithms???
Is this possible to do using logarithms???

RE: Print and remove leaf nodes until root node left
would a queue work? a bfs till you get to a leaf node. delete it then at the end just recur the root node. stop when root is nullptr??????

RE: Custom Iterator for a given List
wouldn't a queue work??? during initialization place all elements >= num in queue;
this way hasnext and next is o(1) only preprocessing is o(n)????