Skip to content

Instantly share code, notes, and snippets.

@zhoutuo
zhoutuo / Longest Substring Without Repeating Characters.cpp
Created February 11, 2013 01:47
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
class Solution {
public:
int lengthOfLongestSubstring(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
unsigned int result = 0;
set<char> table;
queue<char> substr;
for(int i = 0; i < s.length(); ++i) {
if(table.find(s[i]) != table.end()) {
@zhoutuo
zhoutuo / Valid Palindrome.cpp
Last active December 12, 2015 09:29
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
class Solution {
public:
bool isPalindrome(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
string tmp = "";
for(int i = 0; i < s.length(); ++i) {
if(!islower(s[i])) {
s[i] = tolower(s[i]);