- 博客(244)
- 收藏
- 关注
转载 各种排序算法的总结
排序算法可以说是一项基本功,解决实际问题中经常遇到,针对实际数据的特点选择合适的排序算法可以使程序获得更高的效率,有时候排序的稳定性还是实际问题中必须考虑的,这篇博客对常见的排序算法进行整理,包括:插入排序、选择排序、冒泡排序、快速排序、堆排序、归并排序、希尔排序、二叉树排序、计数排序、桶排序、基数排序。 代码都经过了CodeBlocks的调试,但是很可能有没注意到的B
2018-02-13 13:30:36
486
转载 LeetCode--Permutations II 全排列之二
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].
2018-01-24 17:26:21
569
转载 LeetCode--Permutations 全排列
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. 这道题是求全排列
2018-01-24 17:19:51
573
转载 LeetCode--powx-n
Implement pow(x, n). 这道题让我们求x的n次方,如果我们只是简单的用个for循环让x乘以自己n次的话,未免也把LeetCode上的想的太简单了,一句话形容图样图森破啊。OJ因超时无法通过,所以我们需要优化我们的算法,使其在更有效的算出结果来。我们可以用递归来折半计算,每次把n缩小一半,这样n最终会缩小到0,任何数的0次方都为1,这时候我们再往回乘,如果此时n是偶
2018-01-24 16:59:41
359
转载 LeetCode--sqrtx
题目描述Implementint sqrt(int x).Compute and return the square root of x.解法一:这道题要求我们求平方根,我们能想到的方法就是算一个候选值的平方,然后和x比较大小,为了缩短查找时间,我们采用二分搜索法来找平方根,由于求平方的结果会很大,可能会超过int的取值范围,所以我们都用long l
2018-01-24 15:44:22
334
转载 LeetCode--restore-ip-addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order
2018-01-23 22:45:45
328
原创 LeetCode--unique-paths-ii
题目描述Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as1and0respecti
2018-01-23 22:21:18
361
原创 LeetCode--unique-paths
题目描述A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is tr
2018-01-23 21:55:39
283
原创 LeetCode--minimum-path-sum
题目描述Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move eithe
2018-01-23 21:23:41
270
原创 LeetCode--climbing-stairs
题目描述You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?分析:假
2018-01-23 21:06:13
361
原创 LeetCode--edit-distance
题目描述Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations pe
2018-01-23 20:50:47
259
转载 LeetCode--Scramble String 爬行字符串
题目:Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ g
2018-01-23 15:16:14
409
原创 LeetCode--gray-code
题目描述The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, prin
2018-01-23 14:11:04
291
原创 LeetCode--decode-ways
题目描述A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determin
2018-01-21 20:15:38
312
转载 LeetCode--Subsets II 子集合之二
题目描述Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must n
2018-01-21 19:54:19
358
原创 LeetCode--subsets
题目描述Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets
2018-01-21 19:37:56
369
原创 LeetCode--interleaving-string
题目描述Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 ="aabcc",s2 ="dbbca",When s3 ="aadbbcbcac", return true.When s3 ="aa
2018-01-21 17:23:57
282
转载 LeetCode--distinct-subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non
2018-01-21 17:07:48
283
原创 LeetCode--triangle
题目描述Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2],
2018-01-21 16:37:11
295
转载 LeetCode--Palindrome Partitioning II 拆分回文串之二
题目:Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Ret
2018-01-21 12:51:53
731
原创 LeetCode--candy
题目描述There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child mus
2018-01-21 12:04:01
230
转载 LeetCode--Word Break II 拆分词句之二
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens =
2018-01-21 11:48:53
328
原创 LeetCode--word-break
题目描述Given a string s and a dictionary of words dict, determine if scan be segmented into a space-separated sequence of one or more dictionary words.For example, givens ="leetcode",
2018-01-21 11:00:14
222
原创 LeetCode--4sum
题目描述Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.
2018-01-20 23:19:46
170
原创 LeetCode--3sum
题目描述Given an array S of n integers, are there elements a, b, cin S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a t
2018-01-20 23:08:08
354
原创 LeetCode--two-sum
题目描述Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up
2018-01-20 22:52:30
172
转载 LeetCode--permutation-sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""312
2018-01-20 22:22:23
205
原创 LeetCode--clone-graph
题目描述Clone an undirected graph. Each node in the graph contains alabeland a list of itsneighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use#as a separ
2018-01-20 22:08:50
262
原创 LeetCode--reverse-integer
题目描述Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to
2018-01-20 21:41:39
202
原创 LeetCode--longest-common-prefix
题目描述Write a function to find the longest common prefix string amongst an array of strings.//先对字符串排序,然后考虑第一个和最后一个的首字符,这两个字符必定是差距最大的两个//(因为排序首先从第一个开始排),如果这两个不等,就返回空,否则,说明所有字符串的首/
2018-01-20 21:20:33
205
转载 LeetCode--single-number-ii
题目描述Given an array of integers, every element appears threetimes except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implem
2018-01-20 21:01:05
343
原创 LeetCode--single-number
题目描述Given an array of integers, every element appears twiceexcept for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it
2018-01-19 23:15:12
212
原创 LeetCode--longest-substring-without-repeating-characters
题目描述Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the
2018-01-19 22:53:48
2617
转载 LeetCode--longest-palindromic-substring
题目描述Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.这道
2018-01-19 22:17:22
168
原创 LeetCode--zigzag-conversion
题目描述The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H
2018-01-18 19:13:45
155
原创 LeetCode--string-to-integer-atoi(atoi库函数的实现)
题目描述Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possi
2018-01-18 16:19:46
269
转载 LeetCode--Regular Expression Matching 正则表达式匹配
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input st
2018-01-18 15:59:43
265
原创 LeetCode--integer-to-roman
题目描述Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.分析:熟悉罗马数字和阿拉伯数字的转换规则,题目算法本身没有太大亮点class Solution {public:
2018-01-18 15:40:25
331
转载 LeetCode--Roman to Integer 罗马数字转化成整数
题目:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999. 罗马数转化成数字问题,我们需要对于罗马数字很熟悉才能完成转换。以下截自百度百科:罗马数字是最早的数字表示方式,比阿拉伯数字早2000多年,起源于罗马
2018-01-18 15:31:33
374
原创 LeetCode--implement-strstr
题目描述Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.分析:直接暴力求解,时间复杂度为O(mn)class Solution {public
2018-01-18 15:19:59
247
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人