diff --git a/.idea/.idea.Leetcode/.idea/indexLayout.xml b/.idea/.idea.Leetcode/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.Leetcode/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Leetcode/.idea/projectSettingsUpdater.xml b/.idea/.idea.Leetcode/.idea/projectSettingsUpdater.xml new file mode 100644 index 0000000..4bb9f4d --- /dev/null +++ b/.idea/.idea.Leetcode/.idea/projectSettingsUpdater.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/.idea.Leetcode/.idea/vcs.xml b/.idea/.idea.Leetcode/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/.idea.Leetcode/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Leetcode/.idea/workspace.xml b/.idea/.idea.Leetcode/.idea/workspace.xml new file mode 100644 index 0000000..da1e619 --- /dev/null +++ b/.idea/.idea.Leetcode/.idea/workspace.xml @@ -0,0 +1,794 @@ + + + + 1. Two Sum/1. Two Sum.csproj + 102. Binary Tree Level Order Traversal/102. Binary Tree Level Order Traversal.csproj + 118. Pascal's Triangle/118. Pascal's Triangle.csproj + 121. Best Time to Buy and Sell Stock/121. Best Time to Buy and Sell Stock.csproj + 142. Linked List Cycle II/142. Linked List Cycle II.csproj + 1480. Running Sum of 1d Array/1480. Running Sum of 1d Array.csproj + 167. Two Sum II - Input Array Is Sorted/167. Two Sum II - Input Array Is Sorted.csproj + 189. Rotate Array/189. Rotate Array.csproj + 2. Add Two Numbers/2. Add Two Numbers.csproj + 205. Isomorphic Strings/205. Isomorphic Strings.csproj + 206. Reverse Linked List/206. Reverse Linked List.csproj + 21. Merge Two Sorted Lists/21. Merge Two Sorted Lists.csproj + 217. Contains Duplicate/217. Contains Duplicate.csproj + 240. Search a 2D Matrix II/240. Search a 2D Matrix II.csproj + 242. Valid Anagram/242. Valid Anagram.csproj + 278. First Bad Version/278. First Bad Version.csproj + 283. Move Zeroes/283. Move Zeroes.csproj + 344. Reverse String/344. Reverse String.csproj + 35. Search Insert Position/35. Search Insert Position.csproj + 350. Intersection of Two Arrays II/350. Intersection of Two Arrays II.csproj + 36. Valid Sudoku/36. Valid Sudoku.csproj + 383. Ransom Note/383. Ransom Note.csproj + 387. First Unique Character in a String/387. First Unique Character in a String.csproj + 392. Is Subsequence/392. Is Subsequence.csproj + 4. Median of Two Sorted Arrays/4. Median of Two Sorted Arrays.csproj + 409. Longest Palindrome/409. Longest Palindrome.csproj + 53. Maximum Subarray/53. Maximum Subarray.csproj + 557. Reverse Words in a String III/557. Reverse Words in a String III.csproj + 566. Reshape the Matrix/566. Reshape the Matrix.csproj + 589. N-ary Tree Preorder Traversal/589. N-ary Tree Preorder Traversal.csproj + 6. Zigzag Conversion/6. Zigzag Conversion.csproj + 704. Binary Search/704. Binary Search.csproj + 724. Find Pivot Index/724. Find Pivot Index.csproj + 74. Search a 2D Matrix/74. Search a 2D Matrix.csproj + 876. Middle of the Linked List/876. Middle of the Linked List.csproj + 88. Merge Sorted Array/88. Merge Sorted Array.csproj + 977. Squares of a Sorted Array/977. Squares of a Sorted Array.csproj + test/test.csproj + + + + + + + + + + + + + + + + + { + "keyToString": { + "ASKED_ADD_EXTERNAL_FILES": "true", + "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "SHARE_PROJECT_CONFIGURATION_FILES": "true", + "WebServerToolWindowFactoryState": "false", + "last_opened_file_path": "/home/nullptr/Projects/dotNET/Leetcode/6. Zigzag Conversion/6. Zigzag Conversion.csproj", + "nodejs_package_manager_path": "npm", + "settings.editor.selected.configurable": "SolutionBuilderGeneralOptionsPage", + "vue.rearranger.settings.migration": "true" + }, + "keyToStringList": { + "rider.external.source.directories": [ + "/home/nullptr/.config/JetBrains/Rider2022.3/resharper-host/DecompilerCache", + "/home/nullptr/.config/JetBrains/Rider2022.3/resharper-host/SourcesCache", + "/home/nullptr/.local/share/Symbols/src" + ] + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1676999551488 + + + + + + + + + \ No newline at end of file diff --git a/2. Add Two Numbers/2. Add Two Numbers.csproj b/2. Add Two Numbers/2. Add Two Numbers.csproj new file mode 100644 index 0000000..8c0c193 --- /dev/null +++ b/2. Add Two Numbers/2. Add Two Numbers.csproj @@ -0,0 +1,11 @@ + + + + Exe + net7.0 + _2._Add_Two_Numbers + enable + enable + + + diff --git a/2. Add Two Numbers/ListNode.cs b/2. Add Two Numbers/ListNode.cs new file mode 100644 index 0000000..e455378 --- /dev/null +++ b/2. Add Two Numbers/ListNode.cs @@ -0,0 +1,10 @@ +namespace _2._Add_Two_Numbers; + +public class ListNode { + public int val; + public ListNode? next; + public ListNode(int val=0, ListNode? next=null) { + this.val = val; + this.next = next; + } +} \ No newline at end of file diff --git a/2. Add Two Numbers/Program.cs b/2. Add Two Numbers/Program.cs new file mode 100644 index 0000000..bc20719 --- /dev/null +++ b/2. Add Two Numbers/Program.cs @@ -0,0 +1,9 @@ +namespace _2._Add_Two_Numbers; + +internal class Program +{ + static void Main(string[] args) + { + + } +} diff --git a/2. Add Two Numbers/Solution.cs b/2. Add Two Numbers/Solution.cs new file mode 100644 index 0000000..80cb7e5 --- /dev/null +++ b/2. Add Two Numbers/Solution.cs @@ -0,0 +1,40 @@ +namespace _2._Add_Two_Numbers; + +public class Solution { + public ListNode AddTwoNumbers(ListNode? l1, ListNode? l2) + { + ListNode? answer = null; + ListNode? answerEnd = answer; + int toNext = 0; + while (l1!=null || l2!=null) + { + int sum = 0; + if (l1 != null) + { + sum += l1.val; + l1 = l1.next; + } + if (l2 != null) + { + sum += l2.val; + l2 = l2.next; + } + + sum += toNext; + toNext = sum / 10; + sum %= 10; + ListNode item = new ListNode(sum); + if (answer == null) + answer = answerEnd = item; + else + { + answerEnd.next = item; + answerEnd = item; + } + } + + if (toNext != 0) + answerEnd.next = new ListNode(toNext); + return answer; + } +} \ No newline at end of file diff --git a/4. Median of Two Sorted Arrays/4. Median of Two Sorted Arrays.csproj b/4. Median of Two Sorted Arrays/4. Median of Two Sorted Arrays.csproj new file mode 100644 index 0000000..20e416b --- /dev/null +++ b/4. Median of Two Sorted Arrays/4. Median of Two Sorted Arrays.csproj @@ -0,0 +1,11 @@ + + + + Exe + net7.0 + _4._Median_of_Two_Sorted_Arrays + enable + enable + + + diff --git a/4. Median of Two Sorted Arrays/Program.cs b/4. Median of Two Sorted Arrays/Program.cs new file mode 100644 index 0000000..469a9bc --- /dev/null +++ b/4. Median of Two Sorted Arrays/Program.cs @@ -0,0 +1,9 @@ +namespace _4._Median_of_Two_Sorted_Arrays; + +internal class Program +{ + static void Main(string[] args) + { + Console.WriteLine(new Solution().FindMedianSortedArrays(new []{1,2}, new []{3,4})); + } +} \ No newline at end of file diff --git a/4. Median of Two Sorted Arrays/Solution.cs b/4. Median of Two Sorted Arrays/Solution.cs new file mode 100644 index 0000000..2dd3f32 --- /dev/null +++ b/4. Median of Two Sorted Arrays/Solution.cs @@ -0,0 +1,32 @@ +namespace _4._Median_of_Two_Sorted_Arrays; + +public class Solution +{ + private int _left = 0; + private int _right = 0; + + public double FindMedianSortedArrays(int[] nums1, int[] nums2) + { + int i1 = 0; + int i2 = 0; + int size = nums1.Length + nums2.Length; + while (i1 + i2 < size / 2+1 && (i1 < nums1.Length || i2 < nums2.Length)) + { + if(i1 < nums1.Length && i2 >= nums2.Length) + Push(nums1[i1++]); + else if(i1 >= nums1.Length && i2 < nums2.Length) + Push(nums2[i2++]); + else if (nums1[i1] < nums2[i2]) + Push(nums1[i1++]); + else + Push(nums2[i2++]); + } + return size%2==1?_right : (_left+_right)/2.0; + } + + private void Push(int num) + { + _left = _right; + _right = num; + } +} \ No newline at end of file diff --git a/6. Zigzag Conversion/6. Zigzag Conversion.csproj b/6. Zigzag Conversion/6. Zigzag Conversion.csproj new file mode 100644 index 0000000..0fb3af2 --- /dev/null +++ b/6. Zigzag Conversion/6. Zigzag Conversion.csproj @@ -0,0 +1,11 @@ + + + + Exe + net7.0 + _6._Zigzag_Conversion + enable + enable + + + diff --git a/6. Zigzag Conversion/Program.cs b/6. Zigzag Conversion/Program.cs new file mode 100644 index 0000000..f2520e8 --- /dev/null +++ b/6. Zigzag Conversion/Program.cs @@ -0,0 +1,9 @@ +namespace _6._Zigzag_Conversion; + +internal class Program +{ + static void Main(string[] args) + { + Console.WriteLine(new Solution().Convert("PAYPALISHIRING", 3)); + } +} \ No newline at end of file diff --git a/6. Zigzag Conversion/Solution.cs b/6. Zigzag Conversion/Solution.cs new file mode 100644 index 0000000..7358b14 --- /dev/null +++ b/6. Zigzag Conversion/Solution.cs @@ -0,0 +1,41 @@ +using System.Text; + +namespace _6._Zigzag_Conversion; + +public class Solution { + public string Convert(string s, int numRows) + { + if (numRows == 1) + return s; + int stepDown = (numRows-2) * 2 + (numRows>0 ? 1 : 0); + int stepTop = 0; + StringBuilder sb = new StringBuilder(); + for (int start = 0; start < numRows; start++) + { + int j = start; + bool toDown = true; + while (j>>>>>> Stashed changes EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE