![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
LTELTY
一句话说完所有事
展开
-
pydicom笔记
处理医疗影像的Python利器:PyDicomhttps://zhuanlan.zhihu.com/p/59413289dicom文件预处理https://blog.csdn.net/qq_35358021/article/details/82857439原创 2019-06-28 19:45:18 · 6956 阅读 · 0 评论 -
151. Reverse Words in a String
Example 1:Input: “the sky is blue”Output: “blue is sky the”Example 2:Input: " hello world! "Output: “world! hello”Explanation: Your reversed string should not contain leading or trailing space...原创 2019-04-24 17:05:37 · 135 阅读 · 0 评论 -
177. Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table.+----+--------+| Id | Salary |+----+--------+| 1 | 100 || 2 | 200 || 3 | 300 |+----+--------+For example, g...原创 2019-05-04 21:28:14 · 211 阅读 · 0 评论 -
178. Rank Scores
Rank ScoresSQL SchemaWrite a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next co...原创 2019-05-04 21:17:59 · 114 阅读 · 0 评论 -
165. Compare Version Numbers
Compare Version NumbersMedium2671055FavoriteShareCompare two version numbers version1 and version2.If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0....原创 2019-04-24 16:29:54 · 100 阅读 · 0 评论 -
164. Maximum Gap
Maximum GapGiven an unsorted array, find the maximum difference between the successive elements in its sorted form.Return 0 if the array contains less than 2 elements.Example 1:Input: [3,6,9,1]...原创 2019-04-24 16:22:20 · 125 阅读 · 0 评论 -
长URL链接转短链接算法
引言最近看到微博的短链接真是很火啊,新浪、腾讯、搜狐等微博网站都加入了短链接的功能。之所以要是使用短链接,主要是因为微博只允许发140 字,如果链接地址太长的话,那么发送的字数将大大减少。短链接的主要职责就是把原始链接很长的地址压缩成只有6 个字母的短链接地址,当我们点击这6 个字母的链接后,我们又可以跳转到原始链接地址。开始以为短链接是按照某种算法把原始链接压缩为短链接,再根据算法从短链接反...原创 2019-04-27 17:29:37 · 11006 阅读 · 2 评论 -
638. Shopping Offers
In LeetCode Store, there are some kinds of items to sell. Each item has a price.However, there are some special offers, and a special offer consists of one or more different kinds of items with a sal...原创 2019-04-18 12:52:40 · 164 阅读 · 0 评论 -
926. Flip String to Monotone Increasing
A string of '0’s and '1’s is monotone increasing if it consists of some number of '0’s (possibly 0),followed by some number of '1’s (also possibly 0.)We are given a string S of '0’s and '1’s, and we...原创 2019-04-18 11:11:28 · 153 阅读 · 0 评论 -
357. Count Numbers with Unique Digits
Count Numbers with Unique DigitsGiven a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.Example:Input: 2Output: 91Explanation: The answer should be the tot...原创 2019-04-18 01:16:48 · 81 阅读 · 0 评论 -
173. Binary Search Tree Iterator
问题实现一个顺序访问有序二叉树的迭代器。Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the B...原创 2019-04-18 00:55:05 · 125 阅读 · 0 评论 -
基数排序、桶排序和计数排序的区别
1.桶排序(Bucket Sort)基本思路是:将待排序元素划分到不同的痛。先扫描一遍序列求出最大值 maxV 和最小值 minV ,设桶的个数为 k ,则把区间 [minV, maxV] 均匀划分成 k 个区间,每个区间就是一个桶。将序列中的元素分配到各自的桶。对每个桶内的元素进行排序。可以选择任意一种排序算法。 将各个桶中的元素合并成一个大的有序序列。假设数据是均匀分布的,则每个桶...原创 2019-04-18 00:11:08 · 15225 阅读 · 0 评论 -
539. Minimum Time Difference
Minimum Time DifferenceGiven a list of 24-hour clock time points in “Hour:Minutes” format, find the minimum minutes difference between any two time points in the list.Example 1:Input: [“23:59”,“0...原创 2019-04-17 23:40:55 · 294 阅读 · 0 评论 -
477. Total Hamming Distance
题目求数组中任意两个元素的二进制表示的汉明距离之和。The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Now your job is to find the total Hamming distance betwe...原创 2019-04-17 23:03:58 · 84 阅读 · 0 评论 -
洗牌算法
1. 背景笔试时,遇到一个算法题:差不多是 在n个不同的数中随机取出不重复的m个数。洗牌算法是将原来的数组进行打散,使原数组的某个数在打散后的数组中的每个位置上等概率的出现,刚好可以解决该问题。2. 洗牌算法由抽牌、换牌和插牌衍生出三种洗牌算法,其中抽牌和换牌分别对应Fisher-Yates Shuffle和Knuth-Durstenfeld Shhuffle算法。2.1 Fisher-Y...原创 2019-04-25 11:36:14 · 2186 阅读 · 0 评论 -
链表的快排、归并排序
引言面试被问到了如何对链表进行排序, 快排不敢写,写了个很低效的插入排序。现在整理一下。解法1、链表的归并排序Node* listMergeSort(Node* head)// n list里面节点的个数{ // if (head->next == NULL) //一个元素就返回 if (head->next == NULL) return head; Nod...原创 2019-04-25 18:00:54 · 214 阅读 · 0 评论 -
Spring笔记
1、springboot获取当前项目路径的地址 System.getProperty("user.dir")2、springboot获取项目根目录classpath//获取根目录File path = new File(ResourceUtils.getURL("classpath:").getPath());if(!path.exists()) path = new File(...原创 2019-05-29 15:35:09 · 95 阅读 · 0 评论 -
线段树总结
参考http://www.cnblogs.com/TenosDoIt/p/3453089.htmlhttp://dongxicheng.org/structure/segment-tree/http://bookshadow.com/weblog/2015/08/13/segment-tree-set-1-sum-of-given-range/Note”对于包含n个叶子节点的完全二叉树,...原创 2019-05-06 18:51:35 · 96 阅读 · 0 评论 -
218. The Skyline Problem
A city’s skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as...原创 2019-05-06 18:39:13 · 276 阅读 · 0 评论 -
295. Find Median from Data Stream
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.For example,[2,3,4], the median is...原创 2019-05-06 17:34:32 · 126 阅读 · 0 评论 -
212. Word Search II
问题Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those hor...原创 2019-05-06 17:10:39 · 141 阅读 · 0 评论 -
191. Number of 1 Bits
问题Write a function that takes an unsigned integer and return the number of ‘1’ bits it has (also known as the Hamming weight).Example 1:Input: 00000000000000000000000000001011Output: 3Explanation...原创 2019-05-06 16:59:15 · 166 阅读 · 0 评论 -
636. Exclusive Time of Functions
题目 计算函数执行时长。On a single threaded CPU, we execute some functions. Each function has a unique id between 0 and N-1.We store logs in timestamp order that describe when a function is entered or exit...原创 2019-05-01 13:35:33 · 180 阅读 · 0 评论 -
210. Course Schedule II
QuestionThere are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed a...原创 2019-05-06 15:40:35 · 89 阅读 · 0 评论 -
134. Gas Station
Gas StationMediumThere are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel fr...原创 2019-05-06 15:28:36 · 119 阅读 · 0 评论 -
318. Maximum Product of Word Lengths
Maximum Product of Word LengthsGiven a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word...原创 2019-05-01 11:29:39 · 121 阅读 · 0 评论 -
168. Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example:1 -> A2 -> B3 -> C...26 -> Z27 -> AA28 -> AB ...Example 1:Input: ...原创 2019-05-06 15:01:38 · 86 阅读 · 0 评论 -
175. Combine Two Tables
Combine Two TablesTable: Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName | varchar |+-------...原创 2019-05-06 14:29:09 · 88 阅读 · 0 评论 -
176. Second Highest Salary
Second Highest SalaryWrite a SQL query to get the second highest salary from the Employee table.+----+--------+| Id | Salary |+----+--------+| 1 | 100 || 2 | 200 || 3 | 300 |+---...原创 2019-05-06 14:21:57 · 132 阅读 · 0 评论 -
623. Add One Row to Tree
623. Add One Row to TreeGiven the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth 1.The adding rule is: g...原创 2019-04-17 22:42:32 · 130 阅读 · 0 评论 -
动态规划解二维多重背包问题
背包问题背包问题是一个很经典的算法问题,根据其复杂程度不同又可分为01背包问题、完全背包问题、多重背包问题、二维背包问题等等。本文讲一讲二维多重背包问题的动态规划解法。01背包问题有N件物品和一个容量为V的背包。第i件物品的体积是a[i],价值是w[i]。求解将哪些物品装入背包可使价值总和最大完全背包问题有N种物品和一个容量为V的背包,每种物品都有无限件可用。第i种物品的体积是a[i],...原创 2019-04-13 22:47:32 · 1578 阅读 · 0 评论 -
数组中只出现一次的数字进阶(其余数字均出现3次)
问题数组中只出现一次的数字进阶(其余数字均出现3次)思路出现3次就不能再用异或的方法了,因为三个相同的数异或还是得到本身。但是还是可以采用位运算的思想,因为出现三次的数字每个位(0或者1)也是出现三次,因此可以每一位的和能够被3整除(对3取余为0)。所以如果把每个数的二进制表示的每一位加起来,对于每一位的和,如果能被3整除,那对应那个只出现一次的数字的那一位就是0,否则对应的那一位是1。...原创 2019-04-08 19:43:13 · 453 阅读 · 0 评论 -
求有环链表的环的起始节点
题目求有环链表环上的第一个节点,即环的起始点。这个问题其实是分为两部分的(1)判断一个链表是不是有循环链存在。我们可以设置两个指针fast,flow 。fast是每次向下移动两个节点,low是每次向下移动一个节点。如果有循环链表他们必然会相遇。这个很好证明了。首先如果如果有循环链表的话,这个两个指针都会进入循环链,在循环链中fast跑得比low快一个节点单位,所以肯定会追上它,那就一定...原创 2019-04-08 19:27:55 · 672 阅读 · 0 评论 -
求两个链表的第一个公共节点
题目输入两个链表,找出它们的第一个公共结点。解法思路介绍了四种解法,复杂度分别是最高的O(n^2)到最低的O(n),最优解法是解法四。第一种解法蛮力(暴力)法,双重循环遍历。代码ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2) { ListNode *p1 = pHead1; ...原创 2019-04-08 19:19:54 · 362 阅读 · 0 评论 -
树中两个结点的最低公共祖先
场景一: 二叉搜索树BST假设是二叉搜索树(二叉搜索树是一个排序的二叉树,左子树的结点小于根结点,右子树的结点大于根结点),故找到一个结点,使其大于左子结点小于右子结点即可。代码public static TreeNode getLastCommonNode(TreeNode pRoot, TreeNode pLeft, TreeNode pRight){ TreeNode treeNod...原创 2019-04-08 19:09:36 · 105 阅读 · 0 评论 -
KMP算法解读
KMP算法全称Knuth-Morris-Pratt算法,根据三个作者Donald Knuth、Vaughan Pratt、James H. Morris的姓氏的首字母拼接而成的。是一种字符串匹配的算法,用于在一个文本串S中查找模式串P的位置。暴力法举例在讲解KMP算法之前,我们先来看暴力破解法是如何运作的,假如我们有一个文本串S和一个模式串P如下:文本串: BBC_ABCDAB_ABCDA...原创 2019-04-07 20:07:13 · 240 阅读 · 0 评论 -
869. Reordered Power of 2
Reordered Power of 2MediumStarting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero.Return true if and only if ...原创 2019-04-11 01:40:03 · 136 阅读 · 0 评论 -
Maximum XOR of Two Numbers in an Array
Maximum XOR of Two Numbers in an ArrayGiven a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.Find the maximum result of ai XOR aj, where 0 ≤ i, j < n.Could you do this...原创 2019-04-11 00:40:32 · 94 阅读 · 0 评论 -
前缀树求数组两个数最大异或值
Maximum XOR of Two Numbers in an ArrayMedium629140FavoriteShareGiven a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.Find the maximum result of ai XOR aj, where 0 ≤ ...原创 2019-04-11 00:29:46 · 265 阅读 · 0 评论 -
756.Pyramid Transition Matrix(层级bp)
Pyramid Transition MatrixWe are stacking blocks to form a pyramid. Each block has a color which is a one letter string, like 'Z'.For every block of color C we place not in the bottom row, we are p...原创 2019-04-10 23:24:53 · 218 阅读 · 0 评论