随笔分类 - 技术目录八[算法]
摘要:public static void Show(){ // 1,2,3,7,8,4,9,5,6 int[][] arr = new int[][]{ new int[]{1,2,3}, new int[]{5,6,7}, new int[]{9,4,8} }; int tr = 0; int tc
阅读全文
摘要:return nums1.Intersect(nums2); 题意:给定两个数组,编写一个函数来计算它们的交集。 c#可以用linq自带的方法返回,顺便看了下微软的内部实现: private static IEnumerable<TSource> IntersectIterator<TSource>
阅读全文
摘要:void MergeSort(int[] arr) { int l = 0; int r = arr.Length-1; MergeSortSub(arr,l,r); } // 1,2 void MergeSortSub(int[] arr,int left,int right) { if(left
阅读全文
摘要:int a = 1; int b = 2; a = a^b; b = a^b; a = a^b; System.Console.WriteLine($"a:{a},b:{b}");
阅读全文
摘要:public static int[] GenerateRandowArray(int maxSize,int maxValue) { Random rd = new Random(); int[] arr = new int[(int)((maxSize+1) * rd.NextDouble ()
阅读全文
摘要:namespace MyLink; public class MyLinkedList { private int _size{get;set;} public class MyTreeNode{ public int val{get;set;} public MyTreeNode next{get
阅读全文
摘要:static void RemoveDataFromList(int[] nums, int val) { int j = nums.Length - 1; int i = 0; while (i <= j) // 感觉总卡在边界上 { if (nums[i] == val) { int temp
阅读全文
摘要:static void Main(string[] args) { // 只能用一次 //IList<HUOWU> hUOWUs = new List<HUOWU>{ // new HUOWU(1,1),new HUOWU(2,5),new HUOWU(3,4), // new HUOWU(6,7)
阅读全文
摘要:/// <summary> /// 机器人 不停尝试 /// </summary> /// <param name="start">开始位置</param> /// <param name="aim">要到的位置</param> /// <param name="n">总的数</param> ///
阅读全文
摘要:public class ClientT { public void Request() { Target target = new AdapterT (); target.Request(); } } public class Target{ public virtual void Request
阅读全文
摘要:public class Solution { public int Fib(int n) { if(n==0 || n ==1) return n; int[] cache = new int[n+1]; cache[0] = 0; cache[1] = 1; for(int i=2;i<=n;i
阅读全文
摘要:public class Solution { public IList<IList<int>> Generate(int numRows) { IList<IList<int>> rt = new List<IList<int>>(20); Queue queue = new Queue(); i
阅读全文
摘要:namespace ZXDC; public class ZXDCS{ /// <summary> /// 前n位有多少中心对称数 /// n=1 1 8 0 /// n=2 11 69 96 88 /// </summary> public static void Show() { var zt
阅读全文
摘要:namespace Binary; public class BinaryTree{ public Node<char> Head{ get; private set; } private string cStr{get;set;} public BinaryTree(string construc
阅读全文
摘要:/** * Definition for singly-linked list. * public class ListNode { * public int val; * public ListNode next; * public ListNode(int x) { val = x; } * }
阅读全文
摘要:public class Solution { public int NumIslands(char[][] grid) { if(grid == null || grid.Count() == 0) return 0; int rowCount = grid.Count(); int colCou
阅读全文
摘要:int NthUglyNumber(int n) { if(n == 1) return 1; List<long> arr = new List<long>(); // 这里用list,它会自己扩容,用数组就需要自己操作这些了 arr.Add(1); int[] uglyArr = {2,3,5}
阅读全文
摘要:public class Solution { public IList<IList<int>> Permute(int[] nums) { var rtItem = new List<int>(); var visited= new Dictionary<int, bool>(); IList<I
阅读全文
摘要:namespace JD; public class JDTest{ public static void Show() { int[] arr = {1,2,3,4,5,6,7}; var root = BuildTree2(arr,0,arr.Length-1); var stack = new
阅读全文
摘要:Stack<int> stack = new Stack<int>(); int temp = 0; HS(92); void HS(int i) { if(i == 100) return; stack.Push(i); Console.WriteLine($"回溯前i:{i}"); HS(i+1
阅读全文