Compare commits

..

10 Commits

12 changed files with 282 additions and 1 deletions

View 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

View 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"));
}
}

View 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>

View 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"))
}

View 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

View 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));
}
}

View 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>

View 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));
}
}

View 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>

View 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).

View 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))
}

View File

@@ -1,5 +1,5 @@
# coding-practice # coding-practice
Practice from Daily Leetcode Practice from Daily Leetcode
ACC : bqq43498@toaik.com ACC : iak64825@jioso.com
Password : ww5&Hy73dgh Password : ww5&Hy73dgh