XnakelX
BAN USER//Copied from my Solution on LeetCode.com
class Solution {
public:
//Scans string for next Vowel starting from the front. Returns index of vowel. Returns -1 for failure
int findNextVowel(string s)
{
static int current = -1;
for (int i = current + 1; i < s.length(); ++i)
{
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u'
|| s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U')
{
current = i;
return current;
}
}
return (current = -1);
}
//Scans string for next Vowel starting from the last element.Returns index of vowel. Returns -1 for failure.
int findVowelback(string s)
{
static int current = s.length();
for (int i = current - 1; i > 0 ; --i)
{
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u'
|| s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U')
{
current = i;
return current;
}
}
return (current = -1);
}
void swap(char& c, char&d)
{
char temp = c;
c = d;
d = temp;
}
//Given a string, it reverses all the vowels
string reverseVowels(string s) {
for (int i = findNextVowel(s), j = findVowelback(s); i < j; i = findNextVowel(s), j = findVowelback(s))
{
swap(s[i], s[j]);
}
return s;
}
};
Node* findNthToLast(Node* head, int n)
{
Node* temp = head;
Node* nthToLast = NULL;
int count = 0;
while(temp != NULL)
{
count++;
temp = temp->next
if(count == n)
{
nthToLast = head;
}
else if (count > n)
{
nthToLast = nthToLast ->next;
}
}
if(nthToLast == NULL)
{
cout << "Error: List size is smaller than N"<<endl;
}
return nthToLast;
}
RepMariaHobbs, Consultant at Adobe
Hi, I am Maria Hobbs from NewYork.Teach career development courses for designated areas. Develop, evaluate and revise course materials ...
RepDonnaWHale, Data Engineer at ADP
Hi, I am passionate writer with a BA in English from the Ohio State University.5+ years of experience writing ...
I think the question is as follows:
- XnakelX June 02, 2016Example:
Input Number: 1993487443
Output Number: 199348743
Here we have 2 consecutive duplicates 99 and 44. Deleting one of the 4 would yield a greater result than deleting the 9. 199348743 vs 193487443
Another Example:
Input number:1100
Output Number: 110
Deleting the 0 would make the number larger than deleting the 1 would. 110 vs 100.