示例#1
0
    bool isPalindrome(string s) {
		// Start typing your C/C++ solution below
		// DO NOT write int main() function
		int len = s.length();
		if (len == 0)
			return true;
		int start = 0, end = len - 1;
		while (start < end)
		{
			while (start <= end && !IsAlphanumeric(s[start]))
				start++;
			if (start >= end)
				return true;
			while (start <= end && !IsAlphanumeric(s[end]))
				end--;
			if (s[start] != s[end])
			{
				int big = max(s[start], s[end]);
				int small = min(s[start], s[end]);
				if (big - small != 32)
					return false;
			}
			start++;
			end--;
		}
		return true;
	}
示例#2
0
static String CollectAlphanumericSuffix(Lexer lexer)
{
	DECLARE_INLINE_STRINGBUILDER(stringBuilder, 16);
	const Byte *src = lexer->src;
	const Byte *end = lexer->end;
	Byte ch;

	if (src >= end || !IsAlphanumeric(ch = *src))
		return NULL;

	INIT_INLINE_STRINGBUILDER(stringBuilder);

	do {
		src++;
		StringBuilder_AppendByte(stringBuilder, ch);
	} while (src < end && IsAlphanumeric(ch = *src));

	return StringBuilder_ToString(stringBuilder);
}