Compare commits
10 Commits
82a37ac33f
...
64e820d47a
Author | SHA1 | Date | |
---|---|---|---|
64e820d47a | |||
7cea903bfc | |||
4a43ef5ae5 | |||
369d518f0c | |||
571e55e40f | |||
778c399313 | |||
80c8ed405c | |||
3b1ffd3b14 | |||
c31ff3820d | |||
2289921833 |
24
202508/2264 largestGoodInteger/C#/C#.sln
Normal file
24
202508/2264 largestGoodInteger/C#/C#.sln
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.2.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "largestGoodInteger", "largestGoodInteger.csproj", "{DF73131C-3A52-FFDC-7C0C-19190AA3E331}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{DF73131C-3A52-FFDC-7C0C-19190AA3E331}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{DF73131C-3A52-FFDC-7C0C-19190AA3E331}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{DF73131C-3A52-FFDC-7C0C-19190AA3E331}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{DF73131C-3A52-FFDC-7C0C-19190AA3E331}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {E9F3A871-90C4-4B8E-81E2-B0AF873694BF}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
63
202508/2264 largestGoodInteger/C#/Program.cs
Normal file
63
202508/2264 largestGoodInteger/C#/Program.cs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
public class Solution {
|
||||||
|
public string LargestGoodInteger(string num)
|
||||||
|
{
|
||||||
|
// var count = 0;
|
||||||
|
// char lastNum = 'a';
|
||||||
|
// var numList = new List<int>();
|
||||||
|
// for (var i = 0; i < num.Length; i++)
|
||||||
|
// {
|
||||||
|
// if (num[i] == lastNum)
|
||||||
|
// {
|
||||||
|
// count++;
|
||||||
|
// if (count == 3)
|
||||||
|
// {
|
||||||
|
// numList.Add(int.Parse(num[i].ToString()));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// count = 1;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// lastNum = num[i];
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (numList.Count == 0)
|
||||||
|
// {
|
||||||
|
// return "";
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// var a = numList.Max().ToString();
|
||||||
|
// return $"{a}{a}{a}";
|
||||||
|
// }
|
||||||
|
|
||||||
|
string max = "";
|
||||||
|
|
||||||
|
for (int i = 0; i < num.Length - 2; i++)
|
||||||
|
{
|
||||||
|
if (num[i] == num[i + 1] && num[i] == num[i + 2])
|
||||||
|
{
|
||||||
|
string current = $"{num[i]}{num[i]}{num[i]}";
|
||||||
|
|
||||||
|
if (max == "") max = current;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (int.Parse(current) > int.Parse(max))
|
||||||
|
max = current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class program
|
||||||
|
{
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
var solution = new Solution();
|
||||||
|
|
||||||
|
Console.WriteLine(solution.LargestGoodInteger("6777133339"));
|
||||||
|
}
|
||||||
|
}
|
10
202508/2264 largestGoodInteger/C#/largestGoodInteger.csproj
Normal file
10
202508/2264 largestGoodInteger/C#/largestGoodInteger.csproj
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
23
202508/2264 largestGoodInteger/GO/main.go
Normal file
23
202508/2264 largestGoodInteger/GO/main.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func LargestGoodInteger(num string) string {
|
||||||
|
max := ""
|
||||||
|
|
||||||
|
for i := 0; i < len(num)-2; i++ {
|
||||||
|
if num[i] == num[i+1] && num[i] == num[i+2] {
|
||||||
|
current := string([]byte{num[i], num[i], num[i]})
|
||||||
|
|
||||||
|
if current > max {
|
||||||
|
max = current
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return max
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println(LargestGoodInteger("7636669283"))
|
||||||
|
}
|
24
202508/2787 numberOfWays/C#/C#.sln
Normal file
24
202508/2787 numberOfWays/C#/C#.sln
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.2.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "numberOfWays", "numberOfWays.csproj", "{1E81E272-AF2C-9CB4-F90B-0AAC263D10DC}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{1E81E272-AF2C-9CB4-F90B-0AAC263D10DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{1E81E272-AF2C-9CB4-F90B-0AAC263D10DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{1E81E272-AF2C-9CB4-F90B-0AAC263D10DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{1E81E272-AF2C-9CB4-F90B-0AAC263D10DC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {AD18FC84-E2FB-4382-96DF-8AE7E50C1401}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
48
202508/2787 numberOfWays/C#/Program.cs
Normal file
48
202508/2787 numberOfWays/C#/Program.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
// knapsack problem
|
||||||
|
public class Solution
|
||||||
|
{
|
||||||
|
public int NumberOfWays(int n, int x)
|
||||||
|
{
|
||||||
|
const int MOD = 1_000_000_007;
|
||||||
|
// list all the powers which smaller than n
|
||||||
|
var powers = new List<int>();
|
||||||
|
var num = 1;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
int pow = (int)Math.Pow(num, x);
|
||||||
|
if (pow > n)
|
||||||
|
break;
|
||||||
|
powers.Add(pow);
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// dynamic programming
|
||||||
|
var dp = new int[n + 1];
|
||||||
|
dp[0] = 1;
|
||||||
|
|
||||||
|
foreach (var power in powers)
|
||||||
|
{
|
||||||
|
for (var i = n; i >= power; i--)
|
||||||
|
{
|
||||||
|
dp[i] = (dp[i] + dp[i - power]) % MOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dp[n];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
var solution = new Solution();
|
||||||
|
|
||||||
|
Console.WriteLine(solution.NumberOfWays(4, 1));
|
||||||
|
Console.WriteLine(solution.NumberOfWays(100, 3));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
10
202508/2787 numberOfWays/C#/numberOfWays.csproj
Normal file
10
202508/2787 numberOfWays/C#/numberOfWays.csproj
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
21
202508/326 isPowerOfThree/C#/Program.cs
Normal file
21
202508/326 isPowerOfThree/C#/Program.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
public class Solution {
|
||||||
|
public bool IsPowerOfThree(int n) {
|
||||||
|
if(n <= 0)
|
||||||
|
return false;
|
||||||
|
if(n == 1)
|
||||||
|
return true;
|
||||||
|
if(n % 3 != 0)
|
||||||
|
return false;
|
||||||
|
return IsPowerOfThree(n/3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class program{
|
||||||
|
static void Main(){
|
||||||
|
var Solution = new Solution();
|
||||||
|
|
||||||
|
Console.WriteLine(Solution.IsPowerOfThree(9));
|
||||||
|
Console.WriteLine(Solution.IsPowerOfThree(0));
|
||||||
|
Console.WriteLine(Solution.IsPowerOfThree(-1));
|
||||||
|
}
|
||||||
|
}
|
10
202508/326 isPowerOfThree/C#/isPowerOfThree.csproj
Normal file
10
202508/326 isPowerOfThree/C#/isPowerOfThree.csproj
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
22
202508/326 isPowerOfThree/description.md
Normal file
22
202508/326 isPowerOfThree/description.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
Given an integer n, return true if it is a power of three. Otherwise, return false.
|
||||||
|
|
||||||
|
An integer n is a power of three, if there exists an integer x such that n == 3x.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Example 1:
|
||||||
|
|
||||||
|
Input: n = 27
|
||||||
|
Output: true
|
||||||
|
Explanation: 27 = 33
|
||||||
|
Example 2:
|
||||||
|
|
||||||
|
Input: n = 0
|
||||||
|
Output: false
|
||||||
|
Explanation: There is no x where 3x = 0.
|
||||||
|
Example 3:
|
||||||
|
|
||||||
|
Input: n = -1
|
||||||
|
Output: false
|
||||||
|
Explanation: There is no x where 3x = (-1).
|
||||||
|
|
26
202508/326 isPowerOfThree/go/app.go
Normal file
26
202508/326 isPowerOfThree/go/app.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type Solution struct{}
|
||||||
|
|
||||||
|
func (s Solution) IsPowerOfThree(n int) bool{
|
||||||
|
if n <= 0{
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if n == 1{
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if n % 3 != 0{
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return s.IsPowerOfThree(n/3)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main(){
|
||||||
|
solution := Solution{}
|
||||||
|
|
||||||
|
fmt.Println(solution.IsPowerOfThree(27))
|
||||||
|
fmt.Println(solution.IsPowerOfThree(0))
|
||||||
|
fmt.Println(solution.IsPowerOfThree(-1))
|
||||||
|
}
|
Reference in New Issue
Block a user