dijana
BAN USERpublic static int missingSubStr(string s) {
int res = 0;
int ind = 0;
bool done = false;
while (!done)
{
ind++;
int i = ind,n,notFound=0;
string str = s.Substring(0, ind);
n = Convert.ToInt32(str);
n++;
while (i < s.Length && notFound < 2) {
str = n.ToString();
for (int j = 0; j < str.Length; j++) {
if (str[j] != s[i]) {
res = n;
notFound++;
i -= j;
break;
}
i++;
}
n++;
}
if (ind == s.Length || notFound == 1) {
done = true;
}
}
return res;
}
It is not a single step but is not an iterative traversal, in a call k should be 1
public static int AddInMid(Elem node,int k) {
int count = 0;
if (node != null)
{
count = AddInMid(node.next, k+1)+1;
if (count==k+1||count==k) {
Elem el = node.next;
node.next = new Elem();
node.next.next = el;
}
}
return count;
}
- dijana June 12, 2020