Recursion
Recursion
// 2)
// 3)
void printPattern(int n)
{
if (n <= 0)
{
cout << n;
return;
}
// 4)
return max;
}
// 5)
if (!isalnum(first))
{
return isPalindrome(str.substr(1));
}
else if (!isalnum(last))
{
return isPalindrome(str.substr(0, str.length() - 1));
}
else if (first != last)
{
return false;
}
// 6)
// 7)
string repeatString(string str, int n) {
if (n <= 0) {
return "";
}
if (isdigit(s[index])) {
int n = s[index] - '0';
index += 2;
string subString = expand(s, index);
result += repeatString(subString, n);
}
else {
result += s[index];
}
result += expand(s, ++index);
return result;
}
string expand(string s) {
size_t index = 0;
return expand(s, index);
}
// 8)
// 9)
#include <cmath>
int myArrayToInt(char* str, int n)
{
if (n == 1)
{
return str[0] - '0';
}
// 10)
// 11)
int mininumBracketAdd(const string& s, size_t index = 0, int openBrackets = 0) {
if (index >= s.length()) {
return openBrackets;
}
int count = 0;
if (s[index] == '(') {
openBrackets++;
} else if (s[index] == ')' && openBrackets > 0) {
openBrackets--;
} else if (s[index] == ')') {
count++;
}
//12)
string reverseSentence(string s) {
if(s.empty())
{
return "";
}
if (spaceIndex == string::npos)
{
return s;
}
if (reversedRemaining.empty())
{
return firstWord;
}
else
{
return reversedRemaining + ' ' + firstWord;
}
}
//13)
int strLen(char* str)
{
if(*str == '\0') return 0;
else
{
return 1 + strLen(str+1);
}
}