leetcode链表计算方法-leetcode-playground:力码解决方案

  • u7_962853
    了解作者
  • 99.7KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-04-16 10:58
    上传日期
leetcode 链表计算方法 力码 :man_technologist: Leetcode 游乐场 Leetcode 网址: # 标题 解决方案 基本思路(一行) 1 1. 散列 O(n) 和 O(n) 空间。 2. 排序 O(n * log n) 并用两个点 O(n) 和 O(1) 空间进行搜索。 2 遍历单链表并做模 10 和 15 对初始数组进行排序,循环遍历数组并选取当前元素,基于两个指针方法解决当前元素右侧的数组的二和问题,目标等于当前元素的负值 26 1. 两个指针,慢跑/快跑方法 27 两个指针,在末尾跳过元素并在开头交换。 35 1. 两个指针,末尾跳过元素,开头交换。 2. 两个指针,都是开头的结果子表指针和全扫描指针 69 二分,懒惰的curr元素计算f(mid) < x < f(mid+1),用除法代替乘法加速计算 75 两个指针接近,用1填充数组的其余部分 88 1.双指针解决方案,在nums1,nums2(=p,q)中存放指向latest未处理的指针。 nums1[pos..pos+mp]->1 写入 nums2 中的 item 并更新 p,q 2. 两个指针的解决方案,从末尾开始避免移
leetcode-playground-master.zip
内容介绍
<h1 align="center"> Leetcode 👨‍💻 </h1> # Leetcode-playground ![.NET Core](https://github.com/NikiforovAll/leetcode-playground/workflows/.NET%20Core/badge.svg) [![codecov](https://codecov.io/gh/NikiforovAll/leetcode-playground/branch/master/graph/badge.svg)](https://codecov.io/gh/NikiforovAll/leetcode-playground-template) [![GitHub License](https://img.shields.io/github/license/nikiforovall/leetcode-playground)](./LICENSE.md) Leetcode url: <https://leetcode.com/nikiforovall/> | # | Title | Solution | Basic idea (One line) | |---| ----- | -------- | --------------------- | | 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/1.two-sum.cs) | 1. Hash O(n) and O(n) space.<br/>2. Sort O(n * log n) and search with two points O(n) and O(1) space.| | 2 | [AddTwoNumbers](https://leetcode.com/problems/add-two-numbers/) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/2.add-two-numbers.cs) | Traverse single-linked list and do modulo 10 sum | | 15 | [3Sum](https://leetcode.com/problems/3sum/) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/15.3-sum.cs) | Sort initial array, loop over array and pick current element, solve two-sum problem based on two pointers method for array to the right of current element with *target* equals to negated value of current element| | 26 | [RemoveDuplicatesFromSortedArray](https://leetcode.com/articles/remove-duplicates-from-sorted-array/) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/26.remove-duplicates-from-sorted-array.cs) | 1. Two pointers, slow/fast runner approach | | 27 | [RemoveElement](https://leetcode.com/problems/remove-element/) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/27.remove-element.cs) | Two pointers, skip element at the end and swap at the start. </br> | | 35 | [SerachInsertPosition](https://leetcode.com/problems/search-insert-position/) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/35.search-insert-position.cs) | 1. Two pointers, skip element at the end and swap at the start. </br> 2. Two pointers, both start at the beginning result-sub-list pointer and full-scan pointer | | 69 | [SqrtX](https://leetcode.com/problems/sqrtx/) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/src\LeetCodeSolutions\69.sqrt-x.cs) | Bisection, lazy curr element calculation f(mid) < x < f(mid+1), use division instead of multiplication to speed up calculation | | 75 | [SortColors](https://leetcode.com/problems/sort-colors/) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/src\LeetCodeSolutions\75.sort-colors.cs) | Two pointers approach, fill the rest of the array with 1 | | 88 | [MergeSortedArray](https://leetcode.com/problems/3sum/) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/88.merge-sorted-array.cs) | 1. Two pointers solution, store pointers to latest not processed in nums1, nums2 (=p,q). Shift nums1[pos..pos+m-p]->1 when item from nums2 is written and update p,q 2. Two pointers solution, start from the end to avoid shift operation| | 96 | [UniqueBinarySearchTrees](https://leetcode.com/problems/unique-binary-search-trees) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/96.unique-binary-search-trees.cs) | Dynamic programming based on catalan number calculation. The goal is to fix one number as root element and calculate number of unique binary trees based on multiplied combinations of subtrees T\[i\]*T\[i - j -1\]| | 130 | [SurroundedRegions](https://leetcode.com/problems/surrounded-regions) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/130.surrounded-regions.cs) | Traverse inner part of board and use dfs to check potential candidates for checking, commit if it is a valid group | | 189 | [RotateArray](https://leetcode.com/problems/rotate-array) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/189.rotate-array.cs) | 1. Shifting with additional O(k) memory </br> 2. Reverse in-place based on pivot element </br> 3. Cyclic replacement | | 200 | [NumberOfIslands](https://leetcode.com/problems/number-of-islands) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/200.number-of-islands.cs) | In-place uncheck of not visited islands via DFS/BFS | | 222 | [CountCompleteTreeNodes](https://leetcode.com/problems/count-complete-tree-nodes) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/src\LeetCodeSolutions\222.count-complete-tree-nodes.cs) | Usage of property of complete tree, depending on height of subtree we could determine the part of tree under construction | | 231 | [PowerOfTwo](https://leetcode.com/problems/power-of-two) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/231.power-of-two.cs) | Bit manipulation | | 275 | [HIndexII](https://leetcode.com/problems/h-index-ii) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/275.h-index-ii.cs) | Binary search for first A\[mid\] >= N - mind, return number of elements to the right of the pointer | | 278 | [FirstBadVersion](https://leetcode.com/problems/first-bad-version) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/278.first-bad-version.cs) | Bisection | | 380 | [InsertDeleteGetRandom1](https://leetcode.com/problems/insert-delete-getrandom-o1/description/) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/380.insert-delete-get-random-o-1.cs) | Maintain map(val -> ind in array) + list, removal is based on swap of last element | | 414 | [ThirdMaximumNumber](https://leetcode.com/problems/third-maximum-number/description/) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/414.third-maximum-number.cs) | Three consecutive counters, stored element shift | | 485 | [ValidateIPAddress](https://leetcode.com/problems/validate-ip-address/description/) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/468.validate-ip-address.cs) | Validation pipeline with the list of heuristics | | 485 | [MaxConsecutiveOnes](https://leetcode.com/problems/third-maximum-number/description/) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/485.max-consecutive-ones.cs) | Sliding window for non-zero part of array and current sum calculation as index diff | | 518 | [CoinChange2](https://leetcode.com/problems/coin-change-2) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/518.coin-change-2.cs) | Classic DP problem, cache total combinations of previous subproblems in a list | | 547 | [FriendCircles](https://leetcode.com/problems/friend-circles) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/547.friend-circles.cs) | Checked DFS nodes | | 904 | [FruitIntoBaskets](https://leetcode.com/problems/fruit-into-baskets) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/904.fruit-into-baskets.cs) | Sliding window, a bunch of pointers to store consecutive sequence of previous latest element | | 977 | [SquaresOfASortedArray](https://leetcode.com/problems/squares-of-a-sorted-array) | [C#](https://github.com/NikiforovAll/leetcode-playground/blob/master/src/LeetCodeSolutions/977.squares-of-a-sorted-array.cs) | 1. Merge sort, array with negative numbers is traversed in a reversed manner </br> 2. Two pointers | | 1004 | [MaxConsecut
评论
    相关推荐
    • 判断链表是否为回文链表leetcode-LeetCode:力码
      判断链表是否为回文链表 leetcode LeetCode 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数 给定一个 32 位有符号整数,将整数中的数字进行反转 判断一个整数是否是回文数。回文数是指正序(从左向右...
    • leetcode
      密码 大批 路径穿越(E) 有效的Mounatin阵列(E) 将所有球移到每个盒子中(M) 算术子数组(M) 树 同一棵树(E) 细绳 编码和解码TinyURL(M) 链表 设计链表(M)
    • leetcode链表删除环-algocpp:cpp中的算法
      链表删除环 alogcpp algorithm from leetcode and book base基础算法 clockangle 计算时钟的夹角 medianlist randomrange 变更随机数生成区间 //random5*5=> 0,5,10,15,20 //+random5 => 0,1,2,3,4,5,6...24 thread_...
    • leetcode链表删除环-practice_on_DS_and_ALGO:实践_on_DS_and_ALGO
      leetcode链表删除环数据结构 动态数组 & & 图表 算法 位操作和数字 - 顺便说一下,无符号数与有符号数的区别 排序的稳定性 — 就地排序以获得 O(1) 空间 (Sort、QuickSelect、Medium of Mediums)——实现所有三种...
    • 判断链表是否为回文链表leetcode-LeetCode:我在leetcode上的一些代码
      判断链表是否为回文链表 leetcode 力码 我在 leetcode 上的一些代码。 这里将描述一些问题。 标签=容易 001.二和 给定一个整数数组,返回两个数字的索引,使它们相加为特定目标。 您可以假设每个输入都只有一个解决...
    • Leetcode-Notes
      Leetcode-Notes 此仓库代表了我刷题的过程和心情~ 2021-4-18 0042: 2021-4-14 0015: 2021-4-10 2021-4-9 0415: 2021-4-7 0160: 2021-4-6 0003: 2021-4-2 0004: 2021-4-1 0025: 2021-3-30 0470: 2021-3-29 0146: 2021...
    • 判断链表是否为回文链表leetcode-lintCode:代码
      判断链表是否为回文链表 leetcode LeetCode 给定一个整数数组和一个目标值,找出数组中和为目标值的两个数 给定一个 32 位有符号整数,将整数中的数字进行反转 判断一个整数是否是回文数。回文数是指正序(从左向右...
    • 判断链表是否为回文链表leetcode-DailyCodingProblem:日常编码问题
      判断链表是否为回文链表 leetcode /** Leetcode 样题练习 */ 无重复字符的最长子串 反转单链表。 你正在爬楼梯。 需要n步才能到达顶部。 每次您可以爬 1 步或 2 步。 你可以通过多少种不同的方式登上顶峰? (注意:...
    • js代码-leetCode--链表 两数相加
      js代码-leetCode--链表 两数相加
    • SIM800C_MQTT.rar
      使用SIM800C模块,使用MQTT协议,连接中国移动onenet平台,能实现数据的订阅、发布、存储等