环形链表II
struct ListNode *detectCycle(struct ListNode *head) {
struct ListNode* fast = head;
struct ListNode* slow = head;
while( fast && fast->next )
{
slow = slow->next;
fast = fast->next->next;
if( slow==fast )
{
struct ListNode* index1 = head;
struct ListNode* index2 = fast;
while( index1 != index2 )
{
index1 = index1->next;
index2 = index2->next;
}
return index1;
}
}
return NULL;
}
有效的字母异位词
bool isAnagram(char * s, char * t){
int record[26]={0};
int i=0;
for( i=0; i<strlen(s); i++ )
record[s[i]-'a']++;
for( i=0; i<strlen(t); i++ )
record[t[i]-'a']--;
for( i=0; i<26; i++ )
{
if(record[i]) return false;
}
return true;
}