Leetcode
Michael-zhou
目前就读于北京邮电大学。
展开
-
Numeric Keypad 解题报告
描述 The numberic keypad on your mobile phone looks like below:1 2 34 5 67 8 9 0Suppose you are holding your mobile phone with single hand. Your thumb points at digit 1. Each time you can 1) press t原创 2016-03-30 09:56:07 · 1154 阅读 · 0 评论 -
Map的按value值排序
Map自带按Key值排序的属性,但很多种情况下我们需要对Map容器进行按Vaule值排序,由于Map没有提供相应的API,我们只有自力更生了。可以利用Pair和自定义排序函数实现,比如我们拿LeetCode上的347题为例,统计一组数中出现次数最多的K个数,代码如下://自定义的pair比较函数,此函数需要定义成全局函数,设计成按second值排序bool cmp(pair<int,int> a,原创 2016-05-15 15:20:15 · 642 阅读 · 0 评论 -
C++ map排序(按照value值排序)
正常的map默认按照key值排序,而map又没有像vector一样的sort()函数,那么如果将map按照value值排序呢?有两种方法:1、将map中的key和value分别存放在一个pair类型的vector中,然后利用vector的sort函数排序,其中map_verb存放我的map值: 最重要是vector的sort函数~~(用sort函数需要引入头文件 #include <algorit转载 2016-04-28 09:51:48 · 1463 阅读 · 0 评论 -
Longest Palindromic Substring [Leetcode 解题报告]
**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.** 题目大意就是给定一个字符串,返回该字符串原创 2016-03-26 19:43:33 · 338 阅读 · 0 评论 -
Permutations II [Leetcode 解题报告]
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].这个题跟Perm原创 2016-03-22 10:20:47 · 380 阅读 · 0 评论 -
Permutations [Leetcode 解题报告]
Given a collection of distinct 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].关于这个题方法很多,我在这里挑了原创 2016-03-22 10:14:55 · 357 阅读 · 0 评论 -
Restore IP Addresses [Leetcode 解题报告]
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 does not原创 2016-03-21 16:32:14 · 256 阅读 · 0 评论 -
Unique Binary Search Trees II [Leetcode 解题报告]
Given n, generate all structurally unique BST’s (binary search trees) that store values 1…n.For example, Given n = 3, your program should return all 5 unique BST’s shown below. 1 3 3原创 2016-03-21 15:17:27 · 243 阅读 · 0 评论 -
Clone Graph [Leetcode解题报告]
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ’s undirected graph serialization: Nodes are labeled uniquely.We use # as a separator for each node,原创 2016-03-21 10:47:15 · 289 阅读 · 0 评论 -
N-Queens [Leetcode解题报告]
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each solut原创 2016-03-20 20:39:15 · 341 阅读 · 0 评论 -
Word Break [Leetcode解题报告]
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s = “leetcode”, dict = [“leet”, “原创 2016-03-20 15:13:40 · 271 阅读 · 0 评论 -
Edit Distance [Leetcode解题报告]
先给一个例子,两个字符串eeba和abca相似度是多少呢,edit distance是一个很好的度量,定义从字符串a变到字符串b,所需要的最少的操作步骤(插入,删除,更改)为两个字符串之间的编辑距离。对于eeba,abca它们之间的编辑距离为3,可以按照上面的操作步骤(不是唯一的)将eeba变到abca,1.将e变为a 2.删除e 3.添加c 共3个步骤。典型的动态规划问题。EDIT[i,j]表示对转载 2016-03-20 11:48:36 · 416 阅读 · 0 评论 -
Subset II [Leetcode 解题报告]
Given a collection of integers that might contain duplicates, nums, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplica原创 2016-03-20 10:53:43 · 437 阅读 · 0 评论 -
Spring Outing 解题报告
题目描述 You class are planning for a spring outing. N people are voting for a destination out of K candidate places. The voting progress is below: First the class vote for the first candidate place. If原创 2016-03-31 10:28:53 · 615 阅读 · 0 评论 -
堆排序
在堆排序中最重要的一个操作就是heapAdjust(),不管是建堆还是维护堆,都需要时时刻刻的进行heapAdjust(),那什么是heapAdjust()呢,这个函数的主要作用是保证堆中的任意父节点都大于其子节点(这里特指大顶堆,还有小顶堆,与之相反),在每次swap()后都需要利用这个函数,来保证新的堆顶的元素也满足这样的特性。在建堆的目的也是为了使得所有节点满足:任意父节点大于其子节点的值,所原创 2016-07-22 19:04:54 · 1454 阅读 · 0 评论