来源:自己LeetCode刷题
696. 计数二进制子串 - 力扣(LeetCode)

#include
int countBinarySubstrings(char * s)
{int sz=strlen(s);int ans=0;int i=1;while (i<=sz-1){char ch1=s[i-1];char ch2=s[i];if (ch1!=ch2){int left=i-1;int right=i;while(left>=0 && right<=sz-1){if (s[left]==ch1 && s[right]==ch2){ans++;left--;right++;}else{break;}}}i++;}return ans;
} #include
#define N 100010
int countBinarySubstrings(char * s)
{int ans=0;int sz=strlen(s);int arr[sz];int sz1=0;int flag=0;char ch=0;int count=0;for (int i=0;i 可以算是一种比较新奇的思路吧。
来源:杭哥
141. 环形链表 - 力扣(LeetCode)

typedef struct ListNode ListNode;
bool hasCycle(struct ListNode *head)
{ListNode* slow=head;ListNode* fast=head;while(fast!=NULL && fast->next!=NULL){slow=slow->next;fast=fast->next->next;if (fast==slow){return true;}}return false;
}判断一个链表是不是是一个环形链表的话,就只需要去设置快慢指针,然后让曼指针每次走一步,快指针每次走两步,这样子的话,快指针会先进入到环当中,然后等到慢指针也进入到这个环当中的时候,这时候相当于在环里面就变成了一个追击问题,由于他们两个的速度差为1,因此他们的距离每次都会缩短1,因此肯定会相遇。
来源:杭哥
142. 环形链表 II - 力扣(LeetCode)

typedef struct ListNode ListNode;
struct ListNode *detectCycle(struct ListNode *head)
{ListNode* slow=head;ListNode* fast=head;while(fast!=NULL && fast->next!=NULL){slow=slow->next;fast=fast->next->next;if (fast==slow){ListNode* cur1=slow;ListNode* cur2=head;while(cur1!=cur2){cur1=cur1->next;cur2=cur2->next;}return cur1;}}return NULL;
}/*** Definition for singly-linked list.* struct ListNode {* int val;* struct ListNode *next;* };*/typedef struct ListNode ListNode;
struct ListNode *detectCycle(struct ListNode *head)
{ListNode* slow=head;ListNode* fast=head;while(fast!=NULL && fast->next!=NULL){slow=slow->next;fast=fast->next->next;if (fast==slow){ListNode* cur1=slow->next;ListNode* head1=cur1;slow->next=NULL;ListNode* cur2=head;int sz1=1;int sz2=1;while(cur2->next!=NULL){sz2++;cur2=cur2->next;}while(cur1->next!=NULL){sz1++;cur1=cur1->next;}int gap=abs(sz1-sz2);ListNode* longlist=head1;ListNode* shortlist=head;if (sz2>sz1){longlist=head;shortlist=head1;}while(gap--){longlist=longlist->next;}while(longlist!=shortlist){longlist=longlist->next;shortlist=shortlist->next;}return longlist;}}return NULL;
}这就需要利用到一个结论,如果一个指针从相遇点出发,一个指针从起始点出发,他们两个行走的速度都是一样的,那么他们必将会在入环点相遇。
其次,链表带环问题如果要求入环点的话,也可以把它转化成相交链表问题,这时候需要人为的把环当中的某一段给人为的斩断,这相当于就形成了两个相交的链表。
来源:自己LeetCode刷题
345. 反转字符串中的元音字母 - 力扣(LeetCode)

#include
#include
char * reverseVowels(char * s)
{int sz=strlen(s);int i=0;int j=sz-1;while(i=0 && s[j]!='a'&&s[j]!='A'&& s[j]!='e'&&s[j]!='E' && s[j]!='i' &&s[j]!='I' && s[j]!='o'&&s[j]!='O'&& s[j]!='u'&&s[j]!='U'){j--;}if (i 双指针呗,有啥好说的。