Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d784864

Browse files
committed
feat(solution): Added more solutions and updated the solutions list
1 parent cd19836 commit d784864

9 files changed

+269
-3
lines changed

0001-1000.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
1-
# Problems 0001-1000
1+
# Problems 0001-1000 <!-- omit from toc -->
22

3-
## Algorithms
3+
## Algorithms <!-- omit from toc -->
44

5-
* [Hash Table](#hash-table)
5+
- [Array](#array)
6+
- [Binary Search](#binary-search)
7+
- [Dynamic Programming](#dynamic-programming)
8+
- [Greedy](#greedy)
9+
- [Hash Table](#hash-table)
10+
- [String](#string)
11+
12+
## Array
13+
14+
| # | Title | Solution | Time | Space | Difficulty | Tag | Note|
15+
|-----|---------------- | --------------- | --------------- | --------------- | ------------- |--------------|-----|
16+
|1672|[Richest Customer Wealth](https://leetcode.com/problems/richest-customer-wealth/)| [C#](./C%23/1672-Richest_Customer_Wealth.cs)| $O(n \cdot m)$| $O(1)$|Easy|||
17+
18+
## Binary Search
19+
20+
| # | Title | Solution | Time | Space | Difficulty | Tag | Note|
21+
|-----|---------------- | --------------- | --------------- | --------------- | ------------- |--------------|-----|
22+
|0704|[Binary Search](https://leetcode.com/problems/binary-search/)| [C#](./C%23/0704-Binary_Search.cs)| $O(log(n))$| $O(1)$|Easy|||
23+
|0278|[First Bad Version](https://leetcode.com/problems/first-bad-version/)| [C#](./C%23/0278-First_Bad_Version.cs)| $O(log(n))$| $O(1)$|Easy|||
24+
25+
## Dynamic Programming
26+
27+
| # | Title | Solution | Time | Space | Difficulty | Tag | Note|
28+
|-----|---------------- | --------------- | --------------- | --------------- | ------------- |--------------|-----|
29+
|0053|[Maximum Subarray](https://leetcode.com/problems/maximum-subarray/)| [C#](./C%23/0053-Maximum_Subarray.cs)| $O(n)$| $O(1)$|Easy||[Kadane's algorithm](https://www.geeksforgeeks.org/largest-sum-contiguous-subarray/)|
30+
31+
## Greedy
32+
33+
| # | Title | Solution | Time | Space | Difficulty | Tag | Note|
34+
|-----|---------------- | --------------- | --------------- | --------------- | ------------- |--------------|-----|
35+
|0011|[Container With Most Water](https://leetcode.com/problems/container-with-most-water/)| [C#](./C%23/0011-Container_With_Most_Water.cs)| $O(n)$| $O(1)$|Medium||[Two Pointers](https://www.geeksforgeeks.org/two-pointers-technique/)|
636

737
## Hash Table
838

@@ -11,3 +41,11 @@
1141
|0001|[Two Sum](https://leetcode.com/problems/two-sum/)| [C#](./C%23/0001-Two_Sum.cs)| $O(n)$| $O(n)$|Easy|||
1242
|0049|[Group Anagrams](https://leetcode.com/problems/group-anagrams/)| [C#](./C%23/0049-Group_Anagrams.cs)| $O(n \cdot m \cdot log(m))$| $O(n \cdot m)$|Medium|||
1343
|0217|[Contains Duplicate](https://leetcode.com/problems/contains-duplicate/)| [C#](./C%23/0217-Contains_Duplicate.cs)| $O(n)$| $O(n)$|Easy|||
44+
45+
## String
46+
47+
| # | Title | Solution | Time | Space | Difficulty | Tag | Note|
48+
|-----|---------------- | --------------- | --------------- | --------------- | ------------- |--------------|-----|
49+
|0242|[Valid Anagram](https://leetcode.com/problems/valid-anagram/)| [C#](./C%23/0242-Valid_Anagram.cs)| $O(n)$| $O(1)$|Easy|||
50+
|0125|[Valid Palindrome](https://leetcode.com/problems/valid-palindrome/)| [C#](./C%23/0125-Valid_Palindrome.cs)| $O(n)$| $O(1)$|Easy||[Two Pointers](https://www.geeksforgeeks.org/two-pointers-technique/)|
51+
|1903|[Largest Odd Number in String](https://leetcode.com/problems/largest-odd-number-in-string/)| [C#](./C%23/1903-Largest_Odd_Number_in_String.cs)| $O(n)$| $O(1)$|Easy|||

C#/0011-Container_With_Most_Water.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// URL: https://leetcode.com/problems/container-with-most-water/
2+
// Time Complexity: O(n)
3+
// Space Complexity: O(1)
4+
5+
public class Solution
6+
{
7+
public int MaxArea(int[] height)
8+
{
9+
// Two pointers approach
10+
int maxArea = 0;
11+
int left = 0;
12+
int right = height.Length - 1;
13+
14+
while (left < right)
15+
{
16+
int width = right - left;
17+
int minHeight = Math.Min(height[left], height[right]);
18+
maxArea = Math.Max(maxArea, width * minHeight);
19+
20+
// Move the pointer pointing to the shorter line
21+
if (height[left] < height[right])
22+
{
23+
left++;
24+
}
25+
else
26+
{
27+
right--;
28+
}
29+
}
30+
31+
return maxArea;
32+
}
33+
}

C#/0053-Maximum_Subarray.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// URL: https://leetcode.com/problems/maximum-subarray/
2+
// Time Complexity: O(n)
3+
// Space Complexity: O(1)
4+
5+
public class Solution
6+
{
7+
public int MaxSubArray(int[] nums)
8+
{
9+
// Kadane's algorithm
10+
int max = int.MinValue;
11+
int maxHere = 0;
12+
13+
for (int i = 0; i < nums.Length; ++i)
14+
{
15+
maxHere = maxHere + nums[i];
16+
17+
if (max < maxHere)
18+
{
19+
max = maxHere;
20+
}
21+
22+
if (maxHere < 0)
23+
{
24+
maxHere = 0;
25+
}
26+
}
27+
28+
return max;
29+
}
30+
}

C#/0125-Valid_Palindrome.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// URL: https://leetcode.com/problems/valid-palindrome/
2+
// Time Complexity: O(n)
3+
// Space Complexity: O(1)
4+
5+
public class Solution
6+
{
7+
public bool IsPalindrome(string s)
8+
{
9+
// Two pointers approach
10+
for (int i = 0, j = s.Length - 1; j > i;)
11+
{
12+
if (!Char.IsLetterOrDigit(s[i]))
13+
{
14+
i++;
15+
continue;
16+
}
17+
18+
if (!Char.IsLetterOrDigit(s[j]))
19+
{
20+
j--;
21+
continue;
22+
}
23+
24+
if (Char.ToLower(s[i++]) != Char.ToLower(s[j--]))
25+
{
26+
return false;
27+
}
28+
}
29+
30+
return true;
31+
}
32+
}

C#/0242-Valid_Anagram.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// URL: https://leetcode.com/problems/valid-anagram/
2+
// Time Complexity: O(n)
3+
// Space Complexity: O(1)
4+
5+
public class Solution
6+
{
7+
public bool IsAnagram(string s, string t)
8+
{
9+
if (s.Length != t.Length)
10+
{
11+
return false;
12+
}
13+
14+
var count = new int[26];
15+
16+
for (int i = 0; i < s.Length; i++)
17+
{
18+
count[s[i] - 'a']++;
19+
count[t[i] - 'a']--;
20+
}
21+
22+
foreach (int c in count)
23+
{
24+
if (c != 0)
25+
{
26+
return false;
27+
}
28+
}
29+
30+
return true;
31+
}
32+
}

C#/0278-First_Bad_Version.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// URL: https://leetcode.com/problems/first-bad-version/
2+
// Time Complexity: O(logn)
3+
// Space Complexity: O(1)
4+
5+
/* The isBadVersion API is defined in the parent class VersionControl.
6+
bool IsBadVersion(int version); */
7+
8+
public class Solution : VersionControl
9+
{
10+
public int FirstBadVersion(int n)
11+
{
12+
int left = 1;
13+
int right = n;
14+
while (left < right)
15+
{
16+
int mid = left + (right - left) / 2;
17+
if (IsBadVersion(mid))
18+
{
19+
right = mid;
20+
}
21+
else
22+
{
23+
left = mid + 1;
24+
}
25+
}
26+
return left;
27+
}
28+
}

C#/0704-Binary_Search.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// URL: https://leetcode.com/problems/binary-search/
2+
// Time Complexity: O(log n)
3+
// Space Complexity: O(1)
4+
5+
public class Solution
6+
{
7+
public int Search(int[] nums, int target)
8+
{
9+
int left = 0;
10+
int right = nums.Length - 1;
11+
while (left <= right)
12+
{
13+
int mid = (left + right) / 2;
14+
if (nums[mid] == target)
15+
{
16+
return mid;
17+
}
18+
if (nums[mid] < target)
19+
{
20+
left = mid + 1;
21+
}
22+
else
23+
{
24+
right = mid - 1;
25+
}
26+
}
27+
return -1;
28+
}
29+
}

C#/1672-Richest_Customer_Wealth.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// URL: https://leetcode.com/problems/richest-customer-wealth/
2+
// Time Complexity: O(n*m)
3+
// Space Complexity: O(1)
4+
5+
public class Solution
6+
{
7+
public int MaximumWealth(int[][] accounts)
8+
{
9+
int largest = 0;
10+
foreach (int[] account in accounts)
11+
{
12+
int sum = 0;
13+
for (int i = 0; i < account.Length; i++)
14+
{
15+
sum += account[i];
16+
}
17+
if (sum > largest)
18+
{
19+
largest = sum;
20+
}
21+
}
22+
return largest;
23+
}
24+
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// URL: https://leetcode.com/problems/largest-odd-number-in-string/
2+
// Time Complexity: O(n)
3+
// Space Complexity: O(1)
4+
5+
public class Solution
6+
{
7+
public string LargestOddNumber(string num)
8+
{
9+
for (int i = num.Length; i > 0; i--)
10+
{
11+
if (Char.GetNumericValue(num[i - 1]) % 2 == 1)
12+
{
13+
return num.Substring(0, i);
14+
}
15+
}
16+
17+
return "";
18+
}
19+
}

0 commit comments

Comments
 (0)