自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(239)
  • 收藏
  • 关注

原创 [leetcode] 89.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, print the sequence of

2015-06-25 14:28:51 341

原创 [leetcode] 85.Maximal Rectangle

题目:Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing all ones and return its area. 题意:给一个二维的数组,数组里的元素是0或者1.找到包含元素全部是1的最大面积的数组。 分析:看到这道题的求最大面积会联想到上一道题,即84道题的求最大面积

2015-06-22 21:23:40 342

原创 [leetcode] 88.Merge Sorted Array

题目: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addit

2015-06-19 10:32:46 307

原创 [leetode] 77.Combinations

题目: Given two integers n and k, return all possible combinations of k numbers out of 1 … n.For example, If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],

2015-06-19 10:29:13 309

原创 [leetcode] 72.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 permitted on a word:

2015-06-11 22:48:50 268

原创 [leetcode] 77.Combinations

题目: Given two integers n and k, return all possible combinations of k numbers out of 1 … n.For example, If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],

2015-06-11 21:32:21 359

原创 [leetcode] 81.Search in Rotated Sorted Array II

题目: Follow up for “Search in Rotated Sorted Array”: What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the arr

2015-06-11 16:32:48 312

原创 [leetcode] 80.Remove Duplicates from Sorted Array II

题目: Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array nums = [1,1,1,2,2,3], Your function should return length = 5, with the first fiv

2015-06-10 16:56:54 293

原创 [leetcode] 82.Remove Duplicates from Sorted List II

题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1-

2015-06-10 10:53:45 417

原创 [leetcode] 83.Remove Duplicates from Sorted List

题目: Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. 比较简单就是删除相同的元素,代码如下:/*

2015-06-09 17:50:05 300

原创 [leetcode] 75.Sort Colors

题目: Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers

2015-06-04 15:35:21 320

原创 [leetcode] 74.Search a 2D Matrix

题目: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right. The first integer of each r

2015-06-03 17:28:51 316

原创 [leetcode] 73.Set Matrix Zeroes

题目: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 题意: 给一个m x n的矩阵,如果某个元素是0,那么就将这个元素所在的行与这个元素所在的列都设为0. 思路: 这道题的一般思路是扫描所有元素,使用一个一维数组line[m]存储哪些行需要设为0,

2015-06-02 17:28:53 334

原创 [leetcode] 71.Simplify Path

题目: Given an absolute path for a file (Unix-style), simplify it.For example, path = “/home/”, => “/home” path = “/a/./b/../../c/”, => “/c” click to show corner cases.Corner Cases: Did you consider

2015-05-20 09:19:24 319

原创 [leetcode] 70.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? 题意: 你可以往上爬一个楼梯或者两格楼梯,到达顶端一共有n

2015-05-19 22:22:34 285

原创 [leetcode] 69.Sqrt(x)

题目: mplement int sqrt(int x).Compute and return the square root of x. 题意: 实现一个求平方的函数,参数是一个整数,返回的也是一个整数。 思路: 这道题很明显的使用二分查找。需要考虑特殊情况,比如说x是最大的整数之类的。 代码参见以下:class Solution {public: int mySqrt(in

2015-05-19 22:15:44 277

原创 [leetcode] 68.Text Justification

题目: Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i

2015-05-12 13:18:09 331

原创 [leetcode] 67.Add Binary

题目: Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”. 题意: 给两个二进制数组的字符串,返回两者的和。 思路: 跟66题有些类似,也需要保存进位,需要考虑最高一位的进位情况。以上。代码如下:class Solut

2015-05-12 09:41:13 359

原创 [leetcode] 66.Plus One

题目: Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list. 题意: 将一个非负的整数按位放在一个数组里

2015-05-12 09:02:39 262

原创 [leetcode] 64.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 either down or right at

2015-05-11 23:42:36 312

原创 [leetcode] 63.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 as 1 and 0 respectively in the grid.F

2015-05-11 23:24:10 274

原创 [leetcode] 62.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 trying to reach the

2015-05-10 16:06:04 315

原创 [leetcode] 60.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”

2015-05-09 22:36:59 336

原创 [leetcode] 57.Insert Interval

题目: Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Examp

2015-05-09 18:12:41 359

原创 [leetcode] 56.Merge Intervals

题目: Given a collection of intervals, merge all overlapping intervals.For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18]. 题意: 给一些区间,合并所有的有重合的区间。比如上面的例子,区间[1,3]与区间[2,6]有重合,那么

2015-05-09 16:48:55 254

原创 [leetcode] 54.Spiral Matrix

题目: Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example, Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Y

2015-05-09 14:07:40 326

原创 [leetcode] 53.Maximum Subarray

题目: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1] ha

2015-05-09 10:17:52 312

原创 [leetcode] 52.N-Queens II

题目:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions. 题意:这道题与第51道题的不同是,这道题只需要返回一共有多少种可能,依旧采用回溯的方法来完成,只需要稍微改写第52道题的代码即可。 以上。

2015-05-09 09:30:24 355

原创 [leetcode] 51.N-Queens

题目: 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.E

2015-05-08 23:06:30 271

原创 [leetcode] 50.Pow(x, n)

题目:Implement pow(x, n). 题意:实现pow函数。 思路:这题需要做的是思考全面。在n=0时,直接返回1.在n>0时,直接让n个x相乘,当然n个x相乘的不需要o(n)的复杂度,只需要o(lgn)的复杂度,比如求100个2相乘,那么我们只要求得50个2相乘的结果,二分法只要o(lgn)复杂度。如果超过double的精度需要返回标记异常,比如面试官会让用一个全局变量记住。在

2015-05-08 10:31:39 362

原创 [leetcode] 49.Anagrams

题目:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case. 题意:给一个字符串数组,找出其中的所有的anagram组。anagram的意思是不同的单词但是含有相同的字符,这样的单词就称作anagram,比如veil,live,

2015-05-08 10:09:34 539

原创 [leetcode] 47.Permutations II

题目: For example, [1,1,2] have the following unique permutations: [1,1,2], [1,2,1], and [2,1,1]. 题意:这道题相对于第46道题的变化是数组里面会有重复出现的元素,所以结题思路需要稍微变化。 思路:比如[-1,2,0,-1,1,0,1]这样数组,我们考虑第一位上可以放的数据一共有-1,0,1,2这四

2015-05-07 22:22:33 346

原创 [leetcode] 46.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]. 题意是:给一个数字的集合,让你找出所有

2015-05-07 20:45:43 361

原创 [leetcode] 45.Jump Game II

问题描述: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is

2015-04-28 17:13:40 407

原创 [leetcode] 55.Jump Game

Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you are

2015-04-28 11:59:29 402

原创 c11新标准之delete,default,override,final

=default,代表使用编译器合成的函数,只有两类函数式编译器合成的。一是构造函数,二是拷贝函数。其中拷贝函数包括:拷贝构造函数,拷贝赋值重载符,析构函数。因为如果类自己实现了某个构造函数,那么编译器就不会为其合成构造函数,只有手动加上=default才行,比如:class A{ public: A(int a):a(a){} A(const A&)=de

2015-03-07 23:11:36 2696

原创 类的控制访问和继承,只讨论易错点

派生类的友员或者成员对于基类protected成员的访问只能通过派生类对象来访问,这个只有的意思是如果通过对象访问只能通过派生类的对象来进行访问。不能通过基类的对象来访问基类中的受保护部分。其本质就是类的对象不能访问其protected成员,即使这个类对象在派生类中。 例子 class Base{ protected: int prot_mem;

2015-03-07 10:46:39 521

原创 归并排序(merge sort)

#includeusing namespace std;void mergeSort(int *, int, int);void merge(int*, int, int, int);void display_arr(int * A, int length);int main(){int oriArr[12] = { 2, 1, 4, 3, 5, 8,

2014-08-14 11:27:24 449

原创 编程之美格格取数(为什么一直是WA,求测试)

#include#includeusing namespace std;struct Node{vector rows;int line;int different_rows;int sum;Node() :line(-1), different_rows(0), sum(0){}Node(int l, int d, int s) :line(l), diffe

2014-04-12 11:47:22 1262 2

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除