Skip to content

Commit a295d5e

Browse files
committed
Linked list cycle had to check fast and fast->next for null lmao not fast and slow poora code shi tha but im a dumbass thats all
1 parent 39de755 commit a295d5e

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

‎141. Linked List Cycle.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* struct ListNode {
4+
* int val;
5+
* ListNode *next;
6+
* ListNode(int x) : val(x), next(NULL) {}
7+
* };
8+
*/
9+
class Solution {
10+
public:
11+
bool hasCycle(ListNode *head)
12+
{
13+
if(head==NULL)
14+
{
15+
return false;
16+
}
17+
ListNode* slow = head;
18+
ListNode* fast = head;
19+
while(fast!=NULL && fast->next!=NULL)
20+
{
21+
slow = slow->next;
22+
fast = fast->next->next;
23+
if(fast==slow)
24+
{
25+
return true;
26+
}
27+
}
28+
return false;
29+
}
30+
};

‎sex

78.8 KB
Binary file not shown.

‎sex.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
string string1 = "comiccomedy";
7+
int count = 0;
8+
for(int i = 0;i<string1.length();i++)
9+
{
10+
bool flag = true;
11+
for(int j = 0;j<string1.length();j++)
12+
{
13+
if(i==j)
14+
{
15+
continue;
16+
}
17+
if(string1[i]==string1[j])
18+
{
19+
flag = false;
20+
}
21+
}
22+
if(flag)
23+
{
24+
count++;
25+
}
26+
}
27+
cout<<count<<endl;
28+
}
29+

0 commit comments

Comments
 (0)