LeetCode记录
持久决心
主攻深度学习&机器视觉领域,希望与各个领域的大佬交流. [Github:https://github.com/PingHGao] [Stack Overflow:https://stackoverflow.com/users/7371707/toughmind ] [CSDN:https://blog.csdn.net/u013832707] [Yuque:https://www.yuque.com/toughmind] [Email:gphsmail@163.com]
展开
-
【转载】时间复杂度 O(log n) 意味着什么?
英文原文:What does the time complexity O(log n) actually mean?中文博客:时间复杂度 O(log n) 意味着什么?正文预先知道算法的复杂度是一回事,了解其后的原理是另一件事情。不管你是计算机科班出身还是想有效解决最优化问题,如果想要用自己的知识解决实际问题,你都必须理解时间复杂度。先从简单直观的 O(1) 和 O(n) 复杂度说起...转载 2019-12-12 08:55:23 · 809 阅读 · 0 评论 -
LeetCode 295题:数据流的中位数(Python中堆的使用)
题目介绍295. Find Median from Data Stream中位数是一个有序数组中中间数的值。如果数组的长度为偶数,中位数就是中间两个数的均值。解法这道题的解法有多种,但是推荐的解法之一就是使用大小堆进行实现。思维过程如下:如果能够直接得到中位数,那么寻找中位数的操作的时间复杂度为O(1)如果能够找到一种合理的插入数据的方法,则数据增加带来的复杂度就会被控制到尽可能的小...原创 2019-12-11 11:17:19 · 1196 阅读 · 0 评论 -
常用的快慢指针背后的原理——龟兔赛跑算法(Floyed Cycle Detection Algorithm)详解!
在刷LeetCode时,我们经常用到快慢指针。那么它背后有怎样的数学原理呢,今天就给大家献丑了。龟兔赛跑简述Floyd判圈算法(Floyd Cycle Detection Algorithm),又称龟兔赛跑算法(Tortoise and Hare Algorithm),是一个可以在有限状态机、迭代函数或者链表上判断是否存在环,以及判断环的起点与长度的算法。原理如图,A为出发点,B为环的入口...原创 2019-12-10 10:34:12 · 2210 阅读 · 0 评论 -
LeetCode 208题:实现前缀树
题目实现前缀树的插入、搜索以及startwith函数。例子:Trie trie = new Trie(); // 构建前缀树trie.insert("apple");trie.search("apple"); // returns truetrie.search("app"); // returns falsetrie.startsWith("app"); // re...原创 2019-11-29 10:51:27 · 224 阅读 · 0 评论 -
LeetCode 160题:寻找两个链表的交点(解法巧妙,且其数学原理应该掌握)
题目Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:begin to intersect at node c1.Example 1:Input: interse...原创 2019-11-19 15:50:59 · 276 阅读 · 0 评论 -
LeetCode152题: 最大乘积子序列(解法解释)
题目给定一个整数数组nums, 求该序列中乘积最大的连续子序列(子序列长度至少为1).example 1Input: [2,3,-2,4]Output: 6说明: 最大值由子序列[2,3]得到example 2Input: [-2,0,-1]Output: -1说明: 最大值由子序列[-1]得到,因为[-2,-1]不是子序列解法对于一个数组,当我们从左到右便利时,我们可以...原创 2019-11-18 17:17:10 · 609 阅读 · 0 评论 -
LeetCode 138题:复制复杂链表(快过98.49%,空间利用少于100%的python解法)
题目原题如下138. Copy List with Random PointerA linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of th...原创 2019-11-13 16:54:02 · 217 阅读 · 0 评论