20240523 Finished
This commit is contained in:
parent
9978017d28
commit
df4e3e929c
13
.idea/.idea.LeetCodeSharp/.idea/.gitignore
vendored
Normal file
13
.idea/.idea.LeetCodeSharp/.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider 忽略的文件
|
||||
/contentModel.xml
|
||||
/.idea.LeetCodeSharp.iml
|
||||
/modules.xml
|
||||
/projectSettingsUpdater.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
4
.idea/.idea.LeetCodeSharp/.idea/encodings.xml
Normal file
4
.idea/.idea.LeetCodeSharp/.idea/encodings.xml
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
8
.idea/.idea.LeetCodeSharp/.idea/indexLayout.xml
Normal file
8
.idea/.idea.LeetCodeSharp/.idea/indexLayout.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
6
.idea/.idea.LeetCodeSharp/.idea/vcs.xml
Normal file
6
.idea/.idea.LeetCodeSharp/.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
46
LeetCodeSharp/Problems/Solution141.cs
Normal file
46
LeetCodeSharp/Problems/Solution141.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
// [141] Linked List Cycle
|
||||
|
||||
using System.Collections.Generic;
|
||||
using LeetCodeSharp.Utils;
|
||||
|
||||
namespace LeetCodeSharp.Problems141
|
||||
{
|
||||
// Submission codes start here
|
||||
|
||||
/**
|
||||
* Definition for singly-linked list.
|
||||
* public class ListNode {
|
||||
* public int val;
|
||||
* public ListNode next;
|
||||
* public ListNode(int x) {
|
||||
* val = x;
|
||||
* next = null;
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
public class Solution
|
||||
{
|
||||
private readonly HashSet<ListNode> _visited = new HashSet<ListNode>();
|
||||
|
||||
public bool HasCycle(ListNode head)
|
||||
{
|
||||
_visited.Clear();
|
||||
ListNode node = head;
|
||||
|
||||
while (node != null)
|
||||
{
|
||||
if (_visited.Contains(node))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
_visited.Add(node);
|
||||
node = node.next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Submission codes end here
|
||||
}
|
Loading…
Reference in New Issue
Block a user