20240826 finished.
This commit is contained in:
		
							
								
								
									
										18
									
								
								LeetCodeSharp.Tests/P690Tests.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								LeetCodeSharp.Tests/P690Tests.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
using LeetCodeSharp.Problems690;
 | 
			
		||||
 | 
			
		||||
namespace LeetCodeSharp.Tests;
 | 
			
		||||
 | 
			
		||||
public class P690Tests
 | 
			
		||||
{
 | 
			
		||||
    [Fact]
 | 
			
		||||
    public void Test1()
 | 
			
		||||
    {
 | 
			
		||||
        var solution = new Solution();
 | 
			
		||||
        Assert.Equal(11,
 | 
			
		||||
            solution.GetImportance([
 | 
			
		||||
                new Employee(1, 5, [2, 3]),
 | 
			
		||||
                new Employee(2, 3, []),
 | 
			
		||||
                new Employee(3, 3, [])
 | 
			
		||||
            ], 1));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -9,6 +9,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LeetCodeSharp.Fetcher", "Le
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeetCodeSharp.Tests", "LeetCodeSharp.Tests\LeetCodeSharp.Tests.csproj", "{97E271FD-7244-4DD2-982C-103DF1E92B7C}"
 | 
			
		||||
EndProject
 | 
			
		||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1F55C3BE-2E8E-47CB-B46A-7B607A196BA1}"
 | 
			
		||||
	ProjectSection(SolutionItems) = preProject
 | 
			
		||||
		justfile = justfile
 | 
			
		||||
		README.md = README.md
 | 
			
		||||
	EndProjectSection
 | 
			
		||||
EndProject
 | 
			
		||||
Global
 | 
			
		||||
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 | 
			
		||||
		Debug|Any CPU = Debug|Any CPU
 | 
			
		||||
 
 | 
			
		||||
@@ -6,4 +6,8 @@
 | 
			
		||||
		<Nullable>disable</Nullable>
 | 
			
		||||
	</PropertyGroup>
 | 
			
		||||
 | 
			
		||||
	<ItemGroup>
 | 
			
		||||
		<InternalsVisibleTo Include="LeetCodeSharp.Tests"/>
 | 
			
		||||
	</ItemGroup>
 | 
			
		||||
 | 
			
		||||
</Project>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										66
									
								
								LeetCodeSharp/Problems/Solution690.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								LeetCodeSharp/Problems/Solution690.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
// [690] Employee Importance
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
 | 
			
		||||
namespace LeetCodeSharp.Problems690
 | 
			
		||||
{
 | 
			
		||||
    // Submission codes start here
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
// Definition for Employee.
 | 
			
		||||
class Employee {
 | 
			
		||||
    public int id;
 | 
			
		||||
    public int importance;
 | 
			
		||||
    public IList<int> subordinates;
 | 
			
		||||
}
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
    class Employee
 | 
			
		||||
    {
 | 
			
		||||
        public int id;
 | 
			
		||||
        public int importance;
 | 
			
		||||
        public IList<int> subordinates;
 | 
			
		||||
 | 
			
		||||
        public Employee(int id, int importance, IList<int> subordinates)
 | 
			
		||||
        {
 | 
			
		||||
            this.id = id;
 | 
			
		||||
            this.importance = importance;
 | 
			
		||||
            this.subordinates = subordinates;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    class Solution
 | 
			
		||||
    {
 | 
			
		||||
        public int GetImportance(IList<Employee> employees, int id)
 | 
			
		||||
        {
 | 
			
		||||
            var map = employees.ToDictionary(e => e.id, e => e);
 | 
			
		||||
 | 
			
		||||
            var visited = new HashSet<int>();
 | 
			
		||||
            var queue = new Queue<int>();
 | 
			
		||||
            queue.Enqueue(id);
 | 
			
		||||
 | 
			
		||||
            var result = 0;
 | 
			
		||||
            while (queue.Count != 0)
 | 
			
		||||
            {
 | 
			
		||||
                var now = queue.Dequeue();
 | 
			
		||||
 | 
			
		||||
                result += map[now].importance;
 | 
			
		||||
                if (!visited.Add(now))
 | 
			
		||||
                {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                foreach (var subordinate in map[now].subordinates)
 | 
			
		||||
                {
 | 
			
		||||
                    queue.Enqueue(subordinate);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return result;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Submission codes end here
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										5
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
# LeetCodeSharp
 | 
			
		||||
 | 
			
		||||
使用C#解决[LeetCode](https://leetcode.cn)上的问题,但是当且仅当对应的题目没有Rust的版本时才会使用。
 | 
			
		||||
 | 
			
		||||
使用`just pull <id>`获得对应ID的题目,使用`just commit`提交到远程仓库,使用`just test`运行测试代码。
 | 
			
		||||
							
								
								
									
										11
									
								
								commit.sh
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								commit.sh
									
									
									
									
									
								
							@@ -1,11 +0,0 @@
 | 
			
		||||
#!/bin/sh
 | 
			
		||||
 | 
			
		||||
set -e
 | 
			
		||||
 | 
			
		||||
time=$(date "+%Y%m%d")
 | 
			
		||||
message="$time Finished"
 | 
			
		||||
 | 
			
		||||
git add -A
 | 
			
		||||
git commit -m "$message"
 | 
			
		||||
 | 
			
		||||
git push
 | 
			
		||||
							
								
								
									
										22
									
								
								justfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								justfile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
#!/usr/bin/env just --justfile
 | 
			
		||||
 | 
			
		||||
build:
 | 
			
		||||
    dotnet build -c Release
 | 
			
		||||
 | 
			
		||||
test:
 | 
			
		||||
    dotnet test
 | 
			
		||||
 | 
			
		||||
commit:
 | 
			
		||||
    #!/usr/bin/env bash
 | 
			
		||||
    set -euxo pipefail
 | 
			
		||||
    time=$(date "+%Y%m%d")
 | 
			
		||||
    message="$time finished."
 | 
			
		||||
 | 
			
		||||
    git add -A
 | 
			
		||||
    git commit -m "$message"
 | 
			
		||||
    git push
 | 
			
		||||
 | 
			
		||||
pull id: build
 | 
			
		||||
    #!/usr/bin/env bash
 | 
			
		||||
    cd LeetCodeSharp
 | 
			
		||||
    dotnet run --project ../LeetCodeSharp.Fetcher/LeetCodeSharp.Fetcher.csproj -- {{id}}
 | 
			
		||||
		Reference in New Issue
	
	Block a user