Skip to content

Commit fda10e0

Browse files
committed
clearing
1 parent 6b079c4 commit fda10e0

25 files changed

+533
-27
lines changed

Backtracking/Class1.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

DailyLeetCode.Test/DailyLeetCode.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<IsPackable>false</IsPackable>
99
<IsTestProject>true</IsTestProject>
10+
<OutputType>Library</OutputType>
1011
</PropertyGroup>
1112

1213
<ItemGroup>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace DailyLeetCode.Test;
2+
3+
public class FindRightInterval436Tests
4+
{
5+
[Fact]
6+
7+
public void FindRightInterval_AllShouldPass()
8+
{
9+
var intervals = new int[3][];
10+
intervals[0] = new int[]{1,4};
11+
intervals[1] = new int[]{2,3};
12+
intervals[2] = new int[]{3,4};
13+
14+
var actual = FindRightInterval436.FindRightInterval(intervals);
15+
var expected = new int[]{-1, 2,-1};
16+
17+
Assert.Equal(expected, actual);
18+
}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace DailyLeetCode.Test;
8+
9+
public class LengthOfLongestFibonacciSubsequenceTest
10+
{
11+
[Theory]
12+
[InlineData(new[] { 1, 2, 3, 4, 5, 6, 7, 8 }, 5)]
13+
[InlineData(new[] { 2, 4, 7, 8, 9, 10, 14, 15, 18, 23, 32, 50 }, 5)]
14+
public void AllShouldPass_LenLongestFibSubseq(int[] arr, int expected)
15+
{
16+
var actual = LengthOfLongestFibonacciSubsequence.LenLongestFibSubseq(arr);
17+
18+
Assert.Equal(expected, actual);
19+
}
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace DailyLeetCode.Test;
2+
3+
public class MaximumOrderedTripletTests
4+
{
5+
[Theory]
6+
//[InlineData(new int[]{12,6,1,2,7}, 77)]
7+
// [InlineData(new int[]{2,3,1}, 0)]
8+
[InlineData(new int[]{1000000,1,1000000}, 999999000000)]
9+
public void AllShouldPass_MaximumTripletValue(int[] nums, long expected)
10+
{
11+
var actual = MaximumOrderedTriplet.MaximumTripletValue_MaxQueue(nums);
12+
13+
Assert.Equal(expected, actual);
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace DailyLeetCode.Test;
2+
3+
public class NumberOfSubsContainAllTreeCharsTests
4+
{
5+
6+
[Theory]
7+
[InlineData("abcabc", 10)]
8+
public void NumberOfSubstrings_AllShouldPass(string s, int expected)
9+
{
10+
var actual = NumberOfSubsContainAllTreeChars.NumberOfSubstrings(s);
11+
Assert.Equal(expected, actual);
12+
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace DailyLeetCode.Test;
2+
3+
public class OneStringSwapTest
4+
{
5+
6+
[Theory]
7+
[InlineData("bank", "kanb", true)]
8+
[InlineData("aa", "ac", false)]
9+
public void AreAlmostEqual_AllShouldPass(string a, string b, bool expected)
10+
{
11+
var actual = OneStringSwap.AreAlmostEqual(a, b);
12+
Assert.Equal(expected, actual);
13+
}
14+
}

DailyLeetCode/FindRightInterval.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace DailyLeetCode;
2+
3+
public class FindRightInterval436
4+
{
5+
public static int[] FindRightInterval(int[][] intervals) {
6+
7+
Array.Sort(intervals, (a, b) => a[0].CompareTo(b[0]));
8+
var ans = new int[intervals.Length];
9+
Array.Fill(ans, -1);
10+
for (int i = 0; i < intervals.Length; i++)
11+
{
12+
var left = 0;
13+
var right = intervals.Length - 1;
14+
var mid = left + (right - left) / 2;
15+
if(intervals[i][1] < intervals[mid][1])
16+
{
17+
while (intervals[i][1] > intervals[mid][1] && mid > 0)
18+
{
19+
left = mid + 1;
20+
mid = left + (right - left) / 2;
21+
}
22+
23+
}
24+
else
25+
{
26+
while (intervals[i][1] < intervals[mid][1] && mid > 0)
27+
{
28+
right = mid - 1;
29+
mid = left + (right - left) / 2;
30+
}
31+
}
32+
33+
ans[i] = mid;
34+
}
35+
36+
return ans;
37+
}
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace DailyLeetCode;
8+
9+
public class LengthOfLongestFibonacciSubsequence
10+
{
11+
public static int LenLongestFibSubseq(int[] arr)
12+
{
13+
int longest = 0;
14+
HashSet<int> sum = new HashSet<int>();
15+
16+
foreach (var a in arr)
17+
{
18+
sum.Add(a);
19+
}
20+
21+
for (int i = 0; i < arr.Length; i++)
22+
{
23+
for (int j = i + 1; j < arr.Length; j++)
24+
{
25+
var prev = arr[j];
26+
var curr = arr[i] + arr[j];
27+
var currlen = 2;
28+
29+
while (sum.Contains(curr))
30+
{
31+
currlen++;
32+
var tmp = curr;
33+
curr = prev + curr;
34+
prev = tmp;
35+
longest = Math.Max(longest, currlen);
36+
}
37+
}
38+
}
39+
40+
return longest;
41+
}
42+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace DailyLeetCode;
2+
3+
public class MaximumOrderedTriplet
4+
{
5+
public static long MaximumTripletValue_MaxQueue(int[] nums)
6+
{
7+
8+
if (nums.Length < 3) return 0;
9+
var maxQueue = new PriorityQueue<int[], long>(comparer: Comparer<long>.Create(((i, i1) => (i < i1) ? 1 : -1)));
10+
11+
for (int i = 0; i < nums.Length; i++)
12+
{
13+
for (int j = i+1; j < nums.Length; j++)
14+
{
15+
for (int k = j+1; k < nums.Length; k++)
16+
{
17+
long val = (nums[i] - nums[j]) * (long) nums[k];
18+
maxQueue.Enqueue([i,j,k], val);
19+
}
20+
}
21+
}
22+
23+
var max = maxQueue.Dequeue();
24+
long value = (nums[max[0]] - nums[max[1]]) * (long)nums[max[2]];
25+
return value < 0 ? 0 : value;
26+
}
27+
28+
public static long MaximumTripletValue_PrefixSum(int[] nums)
29+
{
30+
return 0;
31+
}
32+
}

0 commit comments

Comments
 (0)