Day6. Namespace style
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
namespace _1._Two_Sum
|
namespace _1._Two_Sum;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -7,4 +7,3 @@
|
|||||||
Console.WriteLine("Hello, World!");
|
Console.WriteLine("Hello, World!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<RootNamespace>_102._Binary_Tree_Level_Order_Traversal</RootNamespace>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
9
102. Binary Tree Level Order Traversal/Program.cs
Normal file
9
102. Binary Tree Level Order Traversal/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace _102._Binary_Tree_Level_Order_Traversal;
|
||||||
|
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello, World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
39
102. Binary Tree Level Order Traversal/Solution.cs
Normal file
39
102. Binary Tree Level Order Traversal/Solution.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
namespace _102._Binary_Tree_Level_Order_Traversal;
|
||||||
|
|
||||||
|
public class Solution
|
||||||
|
{
|
||||||
|
public IList<IList<int>> LevelOrder(TreeNode root)
|
||||||
|
{
|
||||||
|
List<IList<int>> output = new List<IList<int>>();
|
||||||
|
RecursiveTraversal(output, new List<TreeNode>() { root });
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RecursiveTraversal(List<IList<int>> output, List<TreeNode> curLevel)
|
||||||
|
{
|
||||||
|
if (curLevel.Count == 0)
|
||||||
|
return;
|
||||||
|
List<int> levelValues = new List<int>();
|
||||||
|
foreach (var n in curLevel)
|
||||||
|
{
|
||||||
|
if (n == null)
|
||||||
|
continue;
|
||||||
|
levelValues.Add(n.val);
|
||||||
|
}
|
||||||
|
if (levelValues.Count == 0)
|
||||||
|
return;
|
||||||
|
output.Add(levelValues);
|
||||||
|
|
||||||
|
List<TreeNode> nextLevel = new List<TreeNode>();
|
||||||
|
foreach (var n in curLevel)
|
||||||
|
{
|
||||||
|
if (n == null)
|
||||||
|
continue;
|
||||||
|
if (n.left != null)
|
||||||
|
nextLevel.Add(n.left);
|
||||||
|
if (n.right != null)
|
||||||
|
nextLevel.Add(n.right);
|
||||||
|
}
|
||||||
|
RecursiveTraversal(output, nextLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
17
102. Binary Tree Level Order Traversal/TreeNode.cs
Normal file
17
102. Binary Tree Level Order Traversal/TreeNode.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
namespace _102._Binary_Tree_Level_Order_Traversal;
|
||||||
|
|
||||||
|
|
||||||
|
//Definition for a binary tree node.
|
||||||
|
public class TreeNode
|
||||||
|
{
|
||||||
|
public int val;
|
||||||
|
public TreeNode? left;
|
||||||
|
public TreeNode? right;
|
||||||
|
public TreeNode(int val = 0, TreeNode? left = null, TreeNode? right = null)
|
||||||
|
{
|
||||||
|
this.val = val;
|
||||||
|
this.left = left;
|
||||||
|
this.right = right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _118._Pascal_s_Triangle
|
namespace _118._Pascal_s_Triangle;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -9,4 +9,3 @@
|
|||||||
Console.WriteLine(String.Join(" ", r));
|
Console.WriteLine(String.Join(" ", r));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _121._Best_Time_to_Buy_and_Sell_Stock
|
namespace _121._Best_Time_to_Buy_and_Sell_Stock;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -7,4 +7,3 @@
|
|||||||
Console.WriteLine(new Solution().MaxProfit(new int[] { 7, 1, 5, 3, 6, 4 }));
|
Console.WriteLine(new Solution().MaxProfit(new int[] { 7, 1, 5, 3, 6, 4 }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _142._Linked_List_Cycle_II
|
namespace _142._Linked_List_Cycle_II;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -12,4 +12,3 @@
|
|||||||
Console.WriteLine(new Solution().DetectCycle(l1)?.val);
|
Console.WriteLine(new Solution().DetectCycle(l1)?.val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _1480._Running_Sum_of_1d_Array
|
namespace _1480._Running_Sum_of_1d_Array;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -7,4 +7,3 @@
|
|||||||
Console.WriteLine("Hello, World!");
|
Console.WriteLine("Hello, World!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
namespace _167._Two_Sum_II___Input_Array_Is_Sorted
|
namespace _167._Two_Sum_II___Input_Array_Is_Sorted;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var arr = new int[] { -2, -3, 4 };
|
var arr = new int[] { -2, -3, 4 };
|
||||||
var res = new Solution().TwoSum(arr, -5);
|
var res = new Solution().TwoSum(arr, -5)!;
|
||||||
Console.WriteLine(String.Join(" ", res));
|
Console.WriteLine(String.Join(" ", res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _189._Rotate_Array
|
namespace _189._Rotate_Array;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -9,4 +9,3 @@
|
|||||||
Console.WriteLine(String.Join(" ", arr));
|
Console.WriteLine(String.Join(" ", arr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _205._Isomorphic_Strings
|
namespace _205._Isomorphic_Strings;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -7,4 +7,3 @@
|
|||||||
Console.WriteLine(new Solution().IsIsomorphic("egg", "foo"));
|
Console.WriteLine(new Solution().IsIsomorphic("egg", "foo"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _206._Reverse_Linked_List
|
namespace _206._Reverse_Linked_List;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -8,4 +8,3 @@
|
|||||||
Console.WriteLine(new Solution().ReverseList(l));
|
Console.WriteLine(new Solution().ReverseList(l));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _21._Merge_Two_Sorted_Lists
|
namespace _21._Merge_Two_Sorted_Lists;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -9,4 +9,3 @@
|
|||||||
Console.WriteLine(new Solution().MergeTwoLists(l1, l2));
|
Console.WriteLine(new Solution().MergeTwoLists(l1, l2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _217._Contains_Duplicate
|
namespace _217._Contains_Duplicate;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -7,4 +7,3 @@
|
|||||||
Console.WriteLine("Hello, World!");
|
Console.WriteLine("Hello, World!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _240._Search_a_2D_Matrix_II
|
namespace _240._Search_a_2D_Matrix_II;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -8,4 +8,3 @@
|
|||||||
Console.WriteLine(new Solution().SearchMatrix(matrix, 2));
|
Console.WriteLine(new Solution().SearchMatrix(matrix, 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
11
242. Valid Anagram/242. Valid Anagram.csproj
Normal file
11
242. Valid Anagram/242. Valid Anagram.csproj
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<RootNamespace>_242._Valid_Anagram</RootNamespace>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
9
242. Valid Anagram/Program.cs
Normal file
9
242. Valid Anagram/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace _242._Valid_Anagram;
|
||||||
|
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello, World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
36
242. Valid Anagram/Solution.cs
Normal file
36
242. Valid Anagram/Solution.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
namespace _242._Valid_Anagram;
|
||||||
|
|
||||||
|
public class Solution
|
||||||
|
{
|
||||||
|
public bool IsAnagram(string s, string t)
|
||||||
|
{
|
||||||
|
Dictionary<char, int> d1 = CountChars(s);
|
||||||
|
Dictionary<char, int> d2 = CountChars(t);
|
||||||
|
if (d1.Count != d2.Count)
|
||||||
|
return false;
|
||||||
|
foreach (var kp in d1)
|
||||||
|
{
|
||||||
|
if (d2.ContainsKey(kp.Key))
|
||||||
|
{
|
||||||
|
if (d2[kp.Key] != kp.Value)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<char, int> CountChars(string str)
|
||||||
|
{
|
||||||
|
Dictionary<char, int> dict = new Dictionary<char, int>();
|
||||||
|
foreach (char ch in str)
|
||||||
|
{
|
||||||
|
if (dict.ContainsKey(ch))
|
||||||
|
dict[ch]++;
|
||||||
|
else
|
||||||
|
dict.Add(ch, 1);
|
||||||
|
}
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _278._First_Bad_Version
|
namespace _278._First_Bad_Version;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -7,4 +7,3 @@
|
|||||||
Console.WriteLine(new Solution().FirstBadVersion(2147483647, 2147483647));
|
Console.WriteLine(new Solution().FirstBadVersion(2147483647, 2147483647));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _283._Move_Zeroes
|
namespace _283._Move_Zeroes;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -9,4 +9,3 @@
|
|||||||
Console.WriteLine(String.Join(" ", test));
|
Console.WriteLine(String.Join(" ", test));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
11
344. Reverse String/344. Reverse String.csproj
Normal file
11
344. Reverse String/344. Reverse String.csproj
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<RootNamespace>_344._Reverse_String</RootNamespace>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
11
344. Reverse String/Program.cs
Normal file
11
344. Reverse String/Program.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace _344._Reverse_String;
|
||||||
|
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
var arr = "Hello, World!".ToArray();
|
||||||
|
new Solution().ReverseString(arr);
|
||||||
|
Console.WriteLine(String.Join("", arr));
|
||||||
|
}
|
||||||
|
}
|
||||||
14
344. Reverse String/Solution.cs
Normal file
14
344. Reverse String/Solution.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace _344._Reverse_String;
|
||||||
|
|
||||||
|
public class Solution
|
||||||
|
{
|
||||||
|
public void ReverseString<T>(T[] arr)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < arr.Length / 2; i++)
|
||||||
|
{
|
||||||
|
T buf = arr[i];
|
||||||
|
arr[i] = arr[arr.Length - 1 - i];
|
||||||
|
arr[arr.Length - 1 - i] = buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
namespace _35._Search_Insert_Position
|
namespace _35._Search_Insert_Position;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _350._Intersection_of_Two_Arrays_II
|
namespace _350._Intersection_of_Two_Arrays_II;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -7,4 +7,3 @@
|
|||||||
Console.WriteLine("Hello, World!");
|
Console.WriteLine("Hello, World!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _36._Valid_Sudoku
|
namespace _36._Valid_Sudoku;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -16,4 +16,3 @@
|
|||||||
Console.WriteLine(new Solution().IsValidSudoku(arr));
|
Console.WriteLine(new Solution().IsValidSudoku(arr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
11
383. Ransom Note/383. Ransom Note.csproj
Normal file
11
383. Ransom Note/383. Ransom Note.csproj
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<RootNamespace>_383._Ransom_Note</RootNamespace>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
9
383. Ransom Note/Program.cs
Normal file
9
383. Ransom Note/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace _383._Ransom_Note;
|
||||||
|
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine(new Solution().CanConstruct("a", "b"));
|
||||||
|
}
|
||||||
|
}
|
||||||
36
383. Ransom Note/Solution.cs
Normal file
36
383. Ransom Note/Solution.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
namespace _383._Ransom_Note;
|
||||||
|
|
||||||
|
public class Solution
|
||||||
|
{
|
||||||
|
public bool CanConstruct(string ransomNote, string magazine)
|
||||||
|
{
|
||||||
|
if (ransomNote.Length > magazine.Length)
|
||||||
|
return false;
|
||||||
|
Dictionary<char, int> note = CountChars(ransomNote);
|
||||||
|
Dictionary<char, int> mag = CountChars(magazine);
|
||||||
|
foreach (var kp in note)
|
||||||
|
{
|
||||||
|
if (mag.ContainsKey(kp.Key))
|
||||||
|
{
|
||||||
|
if (mag[kp.Key] < kp.Value)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<char, int> CountChars(string str)
|
||||||
|
{
|
||||||
|
Dictionary<char, int> dict = new Dictionary<char, int>();
|
||||||
|
foreach (char ch in str)
|
||||||
|
{
|
||||||
|
if (dict.ContainsKey(ch))
|
||||||
|
dict[ch]++;
|
||||||
|
else
|
||||||
|
dict.Add(ch, 1);
|
||||||
|
}
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<RootNamespace>_387._First_Unique_Character_in_a_String</RootNamespace>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
9
387. First Unique Character in a String/Program.cs
Normal file
9
387. First Unique Character in a String/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace _387._First_Unique_Character_in_a_String;
|
||||||
|
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine(new Solution().FirstUniqChar("Leetcode"));
|
||||||
|
}
|
||||||
|
}
|
||||||
20
387. First Unique Character in a String/Solution.cs
Normal file
20
387. First Unique Character in a String/Solution.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
namespace _387._First_Unique_Character_in_a_String;
|
||||||
|
|
||||||
|
public class Solution
|
||||||
|
{
|
||||||
|
public int FirstUniqChar(string s)
|
||||||
|
{
|
||||||
|
Dictionary<char, int> dic = new Dictionary<char, int>();
|
||||||
|
foreach (char ch in s)
|
||||||
|
{
|
||||||
|
if (dic.ContainsKey(ch))
|
||||||
|
dic[ch]++;
|
||||||
|
else
|
||||||
|
dic.Add(ch, 1);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < s.Length; i++)
|
||||||
|
if (dic[s[i]] == 1)
|
||||||
|
return i;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _392._Is_Subsequence
|
namespace _392._Is_Subsequence;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -7,4 +7,3 @@
|
|||||||
Console.WriteLine("Hello, World!");
|
Console.WriteLine("Hello, World!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _409._Longest_Palindrome
|
namespace _409._Longest_Palindrome;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -7,4 +7,3 @@
|
|||||||
Console.WriteLine(new Solution().LongestPalindrome("bb"));
|
Console.WriteLine(new Solution().LongestPalindrome("bb"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _53._Maximum_Subarray
|
namespace _53._Maximum_Subarray;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -7,4 +7,3 @@
|
|||||||
Console.WriteLine("Hello, World!");
|
Console.WriteLine("Hello, World!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<RootNamespace>_557._Reverse_Words_in_a_String_III</RootNamespace>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
9
557. Reverse Words in a String III/Program.cs
Normal file
9
557. Reverse Words in a String III/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace _557._Reverse_Words_in_a_String_III;
|
||||||
|
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine(new Solution().ReverseWords("God Ding"));
|
||||||
|
}
|
||||||
|
}
|
||||||
25
557. Reverse Words in a String III/Solution.cs
Normal file
25
557. Reverse Words in a String III/Solution.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace _557._Reverse_Words_in_a_String_III;
|
||||||
|
|
||||||
|
public class Solution
|
||||||
|
{
|
||||||
|
public string ReverseWords(string s)
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < s.Length; i++)
|
||||||
|
{
|
||||||
|
if (s[i] == ' ')
|
||||||
|
sb.Append(' ');
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int startIndex = i;
|
||||||
|
while (i < s.Length - 1 && s[i + 1] != ' ')
|
||||||
|
i++;
|
||||||
|
for (int r = i; r >= startIndex; r--)
|
||||||
|
sb.Append(s[r]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _566._Reshape_the_Matrix
|
namespace _566._Reshape_the_Matrix;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -9,4 +9,3 @@
|
|||||||
Console.WriteLine(String.Join(" ", row));
|
Console.WriteLine(String.Join(" ", row));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<RootNamespace>_589._N_ary_Tree_Preorder_Traversal</RootNamespace>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
21
589. N-ary Tree Preorder Traversal/Node.cs
Normal file
21
589. N-ary Tree Preorder Traversal/Node.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
namespace _589._N_ary_Tree_Preorder_Traversal;
|
||||||
|
|
||||||
|
// Definition for a Node.
|
||||||
|
public class Node
|
||||||
|
{
|
||||||
|
public int val;
|
||||||
|
public IList<Node>? children;
|
||||||
|
|
||||||
|
public Node() { }
|
||||||
|
|
||||||
|
public Node(int _val)
|
||||||
|
{
|
||||||
|
val = _val;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node(int _val, IList<Node> _children)
|
||||||
|
{
|
||||||
|
val = _val;
|
||||||
|
children = _children;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
589. N-ary Tree Preorder Traversal/Program.cs
Normal file
9
589. N-ary Tree Preorder Traversal/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace _589._N_ary_Tree_Preorder_Traversal;
|
||||||
|
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello, World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
22
589. N-ary Tree Preorder Traversal/Solution.cs
Normal file
22
589. N-ary Tree Preorder Traversal/Solution.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
namespace _589._N_ary_Tree_Preorder_Traversal;
|
||||||
|
|
||||||
|
public class Solution
|
||||||
|
{
|
||||||
|
public IList<int> Preorder(Node root)
|
||||||
|
{
|
||||||
|
List<int> list = new List<int>();
|
||||||
|
RecursiveTraversal(list, root);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RecursiveTraversal(List<int> output, Node cur)
|
||||||
|
{
|
||||||
|
if (cur == null)
|
||||||
|
return;
|
||||||
|
output.Add(cur.val);
|
||||||
|
if (cur.children == null)
|
||||||
|
return;
|
||||||
|
foreach (var child in cur.children)
|
||||||
|
RecursiveTraversal(output, child);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _704._Binary_Search
|
namespace _704._Binary_Search;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -7,4 +7,3 @@
|
|||||||
Console.WriteLine(new Solution().Search(new int[] { -1, 0, 3, 5, 9, 12 }, 13));
|
Console.WriteLine(new Solution().Search(new int[] { -1, 0, 3, 5, 9, 12 }, 13));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _724._Find_Pivot_Index
|
namespace _724._Find_Pivot_Index;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -8,4 +8,3 @@
|
|||||||
sol.PivotIndex(new int[] { 1, 4, 2 });
|
sol.PivotIndex(new int[] { 1, 4, 2 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _74._Search_a_2D_Matrix
|
namespace _74._Search_a_2D_Matrix;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -8,4 +8,3 @@
|
|||||||
Console.WriteLine(new Solution().SearchMatrix(matrix, 1));
|
Console.WriteLine(new Solution().SearchMatrix(matrix, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _876._Middle_of_the_Linked_List
|
namespace _876._Middle_of_the_Linked_List;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -10,4 +10,3 @@
|
|||||||
Console.WriteLine(new Solution().MiddleNode(l2).val);
|
Console.WriteLine(new Solution().MiddleNode(l2).val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _88._Merge_Sorted_Array
|
namespace _88._Merge_Sorted_Array;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -11,4 +11,3 @@
|
|||||||
Console.WriteLine(String.Join(" ", n1));
|
Console.WriteLine(String.Join(" ", n1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace _977._Squares_of_a_Sorted_Array
|
namespace _977._Squares_of_a_Sorted_Array;
|
||||||
{
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -8,4 +8,3 @@
|
|||||||
Console.WriteLine(String.Join(" ", res));
|
Console.WriteLine(String.Join(" ", res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
46
Leetcode.sln
46
Leetcode.sln
@@ -53,9 +53,23 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "74. Search a 2D Matrix", "7
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "240. Search a 2D Matrix II", "240. Search a 2D Matrix II\240. Search a 2D Matrix II.csproj", "{F47BA875-AF2F-4D00-AB75-A62A6E31387C}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "240. Search a 2D Matrix II", "240. Search a 2D Matrix II\240. Search a 2D Matrix II.csproj", "{F47BA875-AF2F-4D00-AB75-A62A6E31387C}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "409. Longest Palindrome", "409. Longest Palindrome\409. Longest Palindrome.csproj", "{F40EDCD6-7BEC-4F1E-BE95-8CD91389122F}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "409. Longest Palindrome", "409. Longest Palindrome\409. Longest Palindrome.csproj", "{F40EDCD6-7BEC-4F1E-BE95-8CD91389122F}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "36. Valid Sudoku", "36. Valid Sudoku\36. Valid Sudoku.csproj", "{C1759C38-D2E4-4869-B6C2-259B26586E11}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "36. Valid Sudoku", "36. Valid Sudoku\36. Valid Sudoku.csproj", "{C1759C38-D2E4-4869-B6C2-259B26586E11}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "344. Reverse String", "344. Reverse String\344. Reverse String.csproj", "{65D5229E-6D7D-41D2-BB68-2EBA40E9DCE3}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "557. Reverse Words in a String III", "557. Reverse Words in a String III\557. Reverse Words in a String III.csproj", "{B3E1C7CD-0992-49BB-B44A-E129912763DB}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "387. First Unique Character in a String", "387. First Unique Character in a String\387. First Unique Character in a String.csproj", "{3B479362-7079-4112-AFA1-3C344E83C8C2}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "383. Ransom Note", "383. Ransom Note\383. Ransom Note.csproj", "{6F43E7FE-AD78-47D6-86FA-33B42DC55882}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "242. Valid Anagram", "242. Valid Anagram\242. Valid Anagram.csproj", "{FBD8C83E-D3F9-4CE3-B5DD-9C326CBC692C}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "589. N-ary Tree Preorder Traversal", "589. N-ary Tree Preorder Traversal\589. N-ary Tree Preorder Traversal.csproj", "{4A8355E0-FF05-4DF3-B735-4B11BEAD95C5}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "102. Binary Tree Level Order Traversal", "102. Binary Tree Level Order Traversal\102. Binary Tree Level Order Traversal.csproj", "{557D8195-C886-4B52-BBC4-285A1C1057FF}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -171,6 +185,34 @@ Global
|
|||||||
{C1759C38-D2E4-4869-B6C2-259B26586E11}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{C1759C38-D2E4-4869-B6C2-259B26586E11}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{C1759C38-D2E4-4869-B6C2-259B26586E11}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{C1759C38-D2E4-4869-B6C2-259B26586E11}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{C1759C38-D2E4-4869-B6C2-259B26586E11}.Release|Any CPU.Build.0 = Release|Any CPU
|
{C1759C38-D2E4-4869-B6C2-259B26586E11}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{65D5229E-6D7D-41D2-BB68-2EBA40E9DCE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{65D5229E-6D7D-41D2-BB68-2EBA40E9DCE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{65D5229E-6D7D-41D2-BB68-2EBA40E9DCE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{65D5229E-6D7D-41D2-BB68-2EBA40E9DCE3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B3E1C7CD-0992-49BB-B44A-E129912763DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B3E1C7CD-0992-49BB-B44A-E129912763DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B3E1C7CD-0992-49BB-B44A-E129912763DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B3E1C7CD-0992-49BB-B44A-E129912763DB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{3B479362-7079-4112-AFA1-3C344E83C8C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{3B479362-7079-4112-AFA1-3C344E83C8C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{3B479362-7079-4112-AFA1-3C344E83C8C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{3B479362-7079-4112-AFA1-3C344E83C8C2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{6F43E7FE-AD78-47D6-86FA-33B42DC55882}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{6F43E7FE-AD78-47D6-86FA-33B42DC55882}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{6F43E7FE-AD78-47D6-86FA-33B42DC55882}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{6F43E7FE-AD78-47D6-86FA-33B42DC55882}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{FBD8C83E-D3F9-4CE3-B5DD-9C326CBC692C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{FBD8C83E-D3F9-4CE3-B5DD-9C326CBC692C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{FBD8C83E-D3F9-4CE3-B5DD-9C326CBC692C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{FBD8C83E-D3F9-4CE3-B5DD-9C326CBC692C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{4A8355E0-FF05-4DF3-B735-4B11BEAD95C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4A8355E0-FF05-4DF3-B735-4B11BEAD95C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4A8355E0-FF05-4DF3-B735-4B11BEAD95C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4A8355E0-FF05-4DF3-B735-4B11BEAD95C5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{557D8195-C886-4B52-BBC4-285A1C1057FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{557D8195-C886-4B52-BBC4-285A1C1057FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{557D8195-C886-4B52-BBC4-285A1C1057FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{557D8195-C886-4B52-BBC4-285A1C1057FF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
Reference in New Issue
Block a user