Day6. Namespace style
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
namespace _1._Two_Sum
|
||||
namespace _1._Two_Sum;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
static void Main(string[] args)
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
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,12 +1,11 @@
|
||||
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)
|
||||
{
|
||||
var res = new Solution().Generate(300);
|
||||
foreach (var r in res)
|
||||
Console.WriteLine(String.Join(" ", r));
|
||||
}
|
||||
var res = new Solution().Generate(300);
|
||||
foreach (var r in res)
|
||||
Console.WriteLine(String.Join(" ", r));
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
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)
|
||||
{
|
||||
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,15 +1,14 @@
|
||||
namespace _142._Linked_List_Cycle_II
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var l1 = new ListNode(3);
|
||||
var l2 = new ListNode(2);
|
||||
namespace _142._Linked_List_Cycle_II;
|
||||
|
||||
l1.next = l2;
|
||||
l2.next = l1;
|
||||
Console.WriteLine(new Solution().DetectCycle(l1)?.val);
|
||||
}
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var l1 = new ListNode(3);
|
||||
var l2 = new ListNode(2);
|
||||
|
||||
l1.next = l2;
|
||||
l2.next = l1;
|
||||
Console.WriteLine(new Solution().DetectCycle(l1)?.val);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
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)
|
||||
{
|
||||
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 res = new Solution().TwoSum(arr, -5);
|
||||
Console.WriteLine(String.Join(" ", res));
|
||||
}
|
||||
var arr = new int[] { -2, -3, 4 };
|
||||
var res = new Solution().TwoSum(arr, -5)!;
|
||||
Console.WriteLine(String.Join(" ", res));
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
namespace _189._Rotate_Array
|
||||
namespace _189._Rotate_Array;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
static void Main(string[] args)
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var arr = new int[] { 1, 2, 3, 4, 5, 6 };
|
||||
new Solution().Rotate(arr, 3);
|
||||
Console.WriteLine(String.Join(" ", arr));
|
||||
}
|
||||
var arr = new int[] { 1, 2, 3, 4, 5, 6 };
|
||||
new Solution().Rotate(arr, 3);
|
||||
Console.WriteLine(String.Join(" ", arr));
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
namespace _205._Isomorphic_Strings
|
||||
namespace _205._Isomorphic_Strings;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
static void Main(string[] args)
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(new Solution().IsIsomorphic("egg", "foo"));
|
||||
}
|
||||
Console.WriteLine(new Solution().IsIsomorphic("egg", "foo"));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
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)
|
||||
{
|
||||
var l = ListNode.Create(new int[] { 1 });
|
||||
Console.WriteLine(new Solution().ReverseList(l));
|
||||
}
|
||||
var l = ListNode.Create(new int[] { 1 });
|
||||
Console.WriteLine(new Solution().ReverseList(l));
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
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)
|
||||
{
|
||||
var l1 = ListNode.Create(new int[] { 1, 2, 4 });
|
||||
var l2 = ListNode.Create(new int[] { 1, 3, 4 });
|
||||
Console.WriteLine(new Solution().MergeTwoLists(l1, l2));
|
||||
}
|
||||
var l1 = ListNode.Create(new int[] { 1, 2, 4 });
|
||||
var l2 = ListNode.Create(new int[] { 1, 3, 4 });
|
||||
Console.WriteLine(new Solution().MergeTwoLists(l1, l2));
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
namespace _217._Contains_Duplicate
|
||||
namespace _217._Contains_Duplicate;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
static void Main(string[] args)
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
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)
|
||||
{
|
||||
int[][] matrix = new int[][] { new int[] { 1, 1, 1, 1 } };
|
||||
Console.WriteLine(new Solution().SearchMatrix(matrix, 2));
|
||||
}
|
||||
int[][] matrix = new int[][] { new int[] { 1, 1, 1, 1 } };
|
||||
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,10 +1,9 @@
|
||||
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)
|
||||
{
|
||||
Console.WriteLine(new Solution().FirstBadVersion(2147483647, 2147483647));
|
||||
}
|
||||
Console.WriteLine(new Solution().FirstBadVersion(2147483647, 2147483647));
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
namespace _283._Move_Zeroes
|
||||
namespace _283._Move_Zeroes;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
static void Main(string[] args)
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var test = new int[] { 0, 1, 0, 3, 12 };
|
||||
new Solution().MoveZeroes(test);
|
||||
Console.WriteLine(String.Join(" ", test));
|
||||
}
|
||||
var test = new int[] { 0, 1, 0, 3, 12 };
|
||||
new Solution().MoveZeroes(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,10 +1,9 @@
|
||||
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)
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
namespace _36._Valid_Sudoku
|
||||
namespace _36._Valid_Sudoku;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
static void Main(string[] args)
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var arr = new char[][] { new char[]{'.', '.', '4', '.', '.', '.', '6', '3', '.'},
|
||||
new char[]{'.', '.', '.', '.', '.', '.', '.', '.', '.'},
|
||||
new char[]{'5', '.', '.', '.', '.', '.', '.', '9', '.'},
|
||||
new char[]{'.', '.', '.', '5', '6', '.', '.', '.', '.'},
|
||||
new char[]{'4', '.', '3', '.', '.', '.', '.', '.', '1'},
|
||||
new char[]{'.', '.', '.', '7', '.', '.', '.', '.', '.'},
|
||||
new char[]{'.', '.', '.', '5', '.', '.', '.', '.', '.'},
|
||||
new char[]{'.', '.', '.', '.', '.', '.', '.', '.', '.'},
|
||||
new char[]{'.', '.', '.', '.', '.', '.', '.', '.', '.'}};
|
||||
Console.WriteLine(new Solution().IsValidSudoku(arr));
|
||||
}
|
||||
var arr = new char[][] { new char[]{'.', '.', '4', '.', '.', '.', '6', '3', '.'},
|
||||
new char[]{'.', '.', '.', '.', '.', '.', '.', '.', '.'},
|
||||
new char[]{'5', '.', '.', '.', '.', '.', '.', '9', '.'},
|
||||
new char[]{'.', '.', '.', '5', '6', '.', '.', '.', '.'},
|
||||
new char[]{'4', '.', '3', '.', '.', '.', '.', '.', '1'},
|
||||
new char[]{'.', '.', '.', '7', '.', '.', '.', '.', '.'},
|
||||
new char[]{'.', '.', '.', '5', '.', '.', '.', '.', '.'},
|
||||
new char[]{'.', '.', '.', '.', '.', '.', '.', '.', '.'},
|
||||
new char[]{'.', '.', '.', '.', '.', '.', '.', '.', '.'}};
|
||||
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,10 +1,9 @@
|
||||
namespace _392._Is_Subsequence
|
||||
namespace _392._Is_Subsequence;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
static void Main(string[] args)
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
namespace _409._Longest_Palindrome
|
||||
namespace _409._Longest_Palindrome;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
static void Main(string[] args)
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(new Solution().LongestPalindrome("bb"));
|
||||
}
|
||||
Console.WriteLine(new Solution().LongestPalindrome("bb"));
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
namespace _53._Maximum_Subarray
|
||||
namespace _53._Maximum_Subarray;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
static void Main(string[] args)
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
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,12 +1,11 @@
|
||||
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)
|
||||
{
|
||||
var res = new Solution().MatrixReshape(new int[][] { new int[] { 1, 2 }, new int[] { 4, 5 } }, 2, 4);
|
||||
foreach (var row in res)
|
||||
Console.WriteLine(String.Join(" ", row));
|
||||
}
|
||||
var res = new Solution().MatrixReshape(new int[][] { new int[] { 1, 2 }, new int[] { 4, 5 } }, 2, 4);
|
||||
foreach (var row in res)
|
||||
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,10 +1,9 @@
|
||||
namespace _704._Binary_Search
|
||||
namespace _704._Binary_Search;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
internal class Program
|
||||
static void Main(string[] args)
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
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,11 +1,10 @@
|
||||
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)
|
||||
{
|
||||
Solution sol = new Solution();
|
||||
sol.PivotIndex(new int[] { 1, 4, 2 });
|
||||
}
|
||||
Solution sol = new Solution();
|
||||
sol.PivotIndex(new int[] { 1, 4, 2 });
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
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)
|
||||
{
|
||||
int[][] matrix = new int[][] { new int[] { 1 } };
|
||||
Console.WriteLine(new Solution().SearchMatrix(matrix, 1));
|
||||
}
|
||||
int[][] matrix = new int[][] { new int[] { 1 } };
|
||||
Console.WriteLine(new Solution().SearchMatrix(matrix, 1));
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
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)
|
||||
{
|
||||
var l1 = ListNode.Create(new int[] { 1, 2, 3, 4, 5 });
|
||||
var l2 = ListNode.Create(new int[] { 1, 2, 3, 4, 5, 6 });
|
||||
Console.WriteLine(new Solution().MiddleNode(l1).val);
|
||||
Console.WriteLine(new Solution().MiddleNode(l2).val);
|
||||
}
|
||||
var l1 = ListNode.Create(new int[] { 1, 2, 3, 4, 5 });
|
||||
var l2 = ListNode.Create(new int[] { 1, 2, 3, 4, 5, 6 });
|
||||
Console.WriteLine(new Solution().MiddleNode(l1).val);
|
||||
Console.WriteLine(new Solution().MiddleNode(l2).val);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
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)
|
||||
{
|
||||
int[] n1 = new int[] { 1, 2, 3, 0, 0, 0 };
|
||||
int[] n2 = new int[] { 2, 5, 6 };
|
||||
Solution solution = new Solution();
|
||||
solution.Merge(n1, 3, n2, n2.Length);
|
||||
Console.WriteLine(String.Join(" ", n1));
|
||||
}
|
||||
int[] n1 = new int[] { 1, 2, 3, 0, 0, 0 };
|
||||
int[] n2 = new int[] { 2, 5, 6 };
|
||||
Solution solution = new Solution();
|
||||
solution.Merge(n1, 3, n2, n2.Length);
|
||||
Console.WriteLine(String.Join(" ", n1));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
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)
|
||||
{
|
||||
var res = new Solution().SortedSquares(new int[] { -7, -2, -1 });
|
||||
Console.WriteLine(String.Join(" ", res));
|
||||
}
|
||||
var res = new Solution().SortedSquares(new int[] { -7, -2, -1 });
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
Global
|
||||
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}.Release|Any CPU.ActiveCfg = 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
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user