算法
一些题解之类的
囧囧兔_
无人认可的人,造就无人能及的成就
展开
-
C#-最长回文子串
给你一个字符串 s,找到 s 中最长的回文子串。示例 1:输入:s = “babad”输出:“bab”解释:“aba” 同样是符合题意的答案。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/longest-palindromic-substringusing System;namespace 最长回文子串进阶{ class Program { static string myfun(string s) { int ma原创 2021-11-27 21:36:32 · 358 阅读 · 0 评论 -
1223. 掷骰子模拟 _动态规划与递归
有一个骰子模拟器会每次投掷的时候生成一个 1 到 6 的随机数。不过我们在使用它时有个约束,就是使得投掷骰子时,连续 掷出数字 i 的次数不能超过 rollMax[i](i 从 1 开始编号)。现在,给你一个整数数组 rollMax 和一个整数 n,请你来计算掷 n 次骰子可得到的不同点数序列的数量。假如两个序列中至少存在一个元素不同,就认为这两个序列是不同的。由于答案可能很大,所以请返回 模 10^9 + 7 之后的结果。来源:力扣(LeetCode)链接:https://leetcode-cn原创 2021-12-24 19:58:44 · 917 阅读 · 0 评论 -
C#-剑指_Offer_26._树的子结构
using System;using System.Collections.Generic;namespace 剑指_Offer_26._树的子结构{ class Program { public class TreeNode { public int val; public TreeNode left; public TreeNode right; public TreeNode(int x) { val = x; } } public static.原创 2021-11-28 18:10:54 · 199 阅读 · 0 评论 -
给定序列,求所有正确的出栈序列
using System;using System.Collections.Generic;namespace 所有出栈可能{ class Program { public static void Myfun(string str,List<string> res) { string temp = ""; Produce(str, temp, res); Distinct(res); for (int i = 0; i < res.Coun原创 2021-11-27 16:35:08 · 632 阅读 · 0 评论 -
数组数字填充问题
有n个数字,能组成多少个互不相同且无重复数字的k位数?都是多少?using System;using System.Collections.Generic;namespace ConsoleApp2{ class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(','); int[] num = Array.ConvertAll<string, int原创 2021-11-21 18:43:04 · 96 阅读 · 0 评论 -
2021-06-04
力扣-两数之和-C#解题思路循环遍历,两两组合,下标相同除外。判断相加是否等于target并将下标储存在数组中,然后返回结果标题相关代码public class Solution { public int[] TwoSum(int[] nums, int target) { //定义结果返回数组 int[] res=new int[2]; //循环遍历,两两组合,下标相同除外 for(int i=0;i<nums.Lengt原创 2021-06-04 18:09:41 · 45 阅读 · 0 评论 -
NC15 求二叉树的层序遍历
using System;using System.Collections.Generic;/*public class TreeNode{ public int val; public TreeNode left; public TreeNode right; public TreeNode (int x) { val = x; }}*/class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可.原创 2021-11-19 16:18:30 · 50 阅读 · 0 评论 -
C#-N皇后
using System;using System.Collections.Generic;namespace N皇后{ class Program { public static List<List<string>> Qdeen(int n) { List<List<string>> res = new List<List<string>>(); List<string> map = new原创 2021-11-26 21:08:33 · 295 阅读 · 0 评论 -
C#-零钱兑换
给你一个整数数组 coins ,表示不同面额的硬币;以及一个整数 amount ,表示总金额。计算并返回可以凑成总金额所需的 最少的硬币个数 。如果没有任何一种硬币组合能组成总金额,返回 -1 。你可以认为每种硬币的数量是无限的。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/coin-changeusing System;namespace 面额对应最少张钱币_动态规划_{ class Program { static int原创 2021-11-27 18:58:04 · 291 阅读 · 0 评论 -
C# 力扣-514-自由之路
题目正常解法public static int FindRotateSteps(string ring, string key) { List<Dictionary<int, int>> res = new List<Dictionary<int, int>>(); Dictionary<int, int> first = new Dictionary<int, int>(); for (int i = 0原创 2022-01-01 16:38:51 · 232 阅读 · 0 评论 -
C#-剑指 Offer 27. 二叉树的镜像
using System;using System.Collections.Generic;namespace 剑指_Offer_27._二叉树的镜像{ class Program { public class TreeNode { public int val; public TreeNode left; public TreeNode right; public TreeNode(int x) { val = x; } } public stati.原创 2021-11-28 20:11:35 · 155 阅读 · 0 评论 -
2021-06-04
leetcode-相交链表-C#题目链接:https://leetcode-cn.com/problems/intersection-of-two-linked-lists/解题思路双循环相关代码/** * Definition for singly-linked list. * public class ListNode { * public int val; * public ListNode next; * public ListNode(int x) {原创 2021-06-04 18:26:19 · 47 阅读 · 0 评论 -
2021-06-04
力扣-两数相加-C#相关代码/** * Definition for singly-linked list. * public class ListNode { * public int val; * public ListNode next; * public ListNode(int val=0, ListNode next=null) { * this.val = val; * this.next = next; *原创 2021-06-04 18:00:04 · 37 阅读 · 0 评论 -
C# 力扣_格雷编码
题目链接n 位格雷码序列 是一个由 2n 个整数组成的序列,其中:每个整数都在范围 [0, 2n - 1] 内(含 0 和 2n - 1)第一个整数是 0一个整数在序列中出现 不超过一次每对 相邻 整数的二进制表示 恰好一位不同 ,且第一个 和 最后一个 整数的二进制表示 恰好一位不同给你一个整数 n ,返回任一有效的 n 位格雷码序列 。我的代码public IList<int> GrayCode(int n) { List<int> res = new原创 2022-01-09 15:52:46 · 226 阅读 · 0 评论 -
排列组合Ann
using System;using System.Collections.Generic;namespace ConsoleApp2{ class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(','); int[] num = Array.ConvertAll<string, int>(str, int.Parse); List原创 2021-11-21 19:12:23 · 1216 阅读 · 0 评论 -
NC45 实现二叉树先序,中序和后序遍历
using System;using System.Collections.Generic;/*public class TreeNode{ public int val; public TreeNode left; public TreeNode right; public TreeNode (int x) { val = x; }}*/class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值.原创 2021-11-19 17:24:13 · 57 阅读 · 0 评论 -
C#_LCP 40. 心算挑战
代码public int MaxmiumScore(int[] cards, int cnt) { List<int> card = new List<int>(cards); card.Sort(); card.Reverse(); int num = 0; List<int> odd = new List<int>(); List<int> even = new List<int>(); int.原创 2022-01-02 01:13:28 · 121 阅读 · 0 评论 -
2021-06-04
leetcode-统计一个圆中点的数目-C#题目链接:https://leetcode-cn.com/problems/queries-on-number-of-points-inside-a-circle/题目:解题思路简单的数组遍历相关代码public class Solution { public int[] CountPoints(int[][] points, int[][] queries) { int length=queries.GetLength(原创 2021-06-04 18:50:34 · 42 阅读 · 0 评论 -
力扣10-正则表达式,递归与动态规划算法
给你一个字符串 s 和一个字符规律 p,请你来实现一个支持 ‘.’ 和 ‘’ 的正则表达式匹配。‘.’ 匹配任意单个字符'’ 匹配零个或多个前面的那一个元素‘?’ 匹配一个或多个前面的那一个元素所谓匹配,是要涵盖 整个 字符串 s的,而不是部分字符串。递归算法public static bool myfun(string s, string p) { if (p.Length == 0) return s.Length == 0; bool match=false; if(原创 2021-12-24 15:48:56 · 127 阅读 · 0 评论