随笔分类 - 技术目录八[算法]
摘要:namespace Test2; // Definition for singly-linked list. public class ListNode { public int val; public ListNode next; public ListNode(int val=0, ListNo
阅读全文
摘要:新建一个集合:删除其中一个元素 List<String> tempList = new List<string>{"水星","金星","地球","火星", "木星","土星","天王星","海王星","冥王星","冥王星"}; tempList.Remove("冥王星"); foreach(var
阅读全文
摘要:你总共有 n 枚硬币,并计划将它们按阶梯状排列。对于一个由 k 行组成的阶梯,其第 i 行必须正好有 i 枚硬币。阶梯的最后一行 可能 是不完整的。 给你一个数字 n ,计算并返回可形成 完整阶梯行 的总行数。 应该首先判断数据源是否是有序的,先二分。 var rs = ArrangeCoins(1
阅读全文
摘要:using System; namespace PX; public class PXTest { public static void Show() { ScoreInfo scoreInfo = new ScoreInfo() { ID = 1, Name = "张三", CSharp = 12
阅读全文
摘要:using System.Collections; using System.Collections.Generic; namespace HS; public class HXTest{ public const int k = 500_001; // 生成一个长度为50万的数组并初始化 publ
阅读全文
摘要:C# 字典、集合、列表的时间复杂度 - 你也很优秀 - 博客园 (cnblogs.com) Dictionary查找Key的源码 private int FindEntry(TKey key) { if( key == null) { ThrowHelper.ThrowArgumentNullExc
阅读全文
摘要:给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。 你可以按任意顺序返回答案。 来源:力扣(LeetCode)链接:htt
阅读全文
摘要:public static int[] SF(int[] Arr) { if(Arr == null || Arr.Length <= 0) return Arr; int j = 0; // j最终停在第一个应该为0的位置上 j++ for(int i=0;i<Arr.Length;i++) {
阅读全文
摘要:namespace NDNGH; public class DTGH{ public static int Change(int n) { int minCount = -1, time = 0; for(int c5 = 0; c5 < n / 5; c5++) { for(int c3 = 0;
阅读全文
摘要:构造树,并求每条路径和 第一步:构造树节点用到的类: public class Node{ public int Val{get;set;} public Node? LNode{get;set;} public Node? RNode{get;set;} public Node(int val)
阅读全文
摘要:20230212,窗外一直下雨,那就静下心来好好学习(保证做事要有思路),做点好吃的。 一 学习算法的步骤: 1.模拟:模拟题目的运行 2.规律:尝试总结出题目的一般规律和特点 3.匹配:找到符合这些特点的数据结构和算法 4.边界:考虑特殊情况 5.画图。 二 案例: 判断一个括号字符串是否有效 一
阅读全文
摘要:Recursion(3); // 1,2,3 Recursion2(3); // 3,2,1 static void Recursion(int num) { if (num > 0) { Console.WriteLine(num); Recursion(num - 1); } } static
阅读全文
摘要:public class 二分查找 { public int[] GetSS(int[] nums, int target) { if (nums.Length == 0) { return new int[] { -1, -1 }; } var fristIndex = GetFristIndex
阅读全文
摘要:public int Search(int[] nums, int target) { int left = 0; int right = nums.Length - 1; while(left <= right) { int middle = left + (right - left)/2; if
阅读全文
摘要:一,递归 不断调用本身,直到某个事件的结尾才结束,然后得到自己想要的结果。 二,递推 从初始点出发,循环事件集,汇总自己需要的结果,返回。 案例一: 一个int[]类型的数组,求和, 递归: //递归 public static int SumByDG(int[] param, int index)
阅读全文