自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 [LeetCode]050-Pow(x,n)

题目: Implement pow(x, n). 实现x的n次幂Solution: 类似于二分的方法来优化“x*x*…x“。 要注意的是当n = INT_MIN时,反过来-n会越界,这时候需要pow(x,INT_MIN) * x 即可。代码如下:class Solution {public: double myPow(double x, int n) {

2016-05-07 19:23:11 567

原创 [LeetCode]049-Group Anagrams

题目: Given an array of strings, group anagrams together.For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return:[ [“ate”, “eat”,”tea”], [“nat”,”tan”], [“bat”] ]Note:For the re

2016-05-07 16:40:26 538

原创 [LeetCode]048-Rotate Image

题目: You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up: Could you do this in-place?Solution: 其实就是矩阵的旋转,找到规律即可,比较简单,代码如下:class Solution {publ

2016-05-07 16:06:40 417

原创 [LeetCode]047-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].

2016-05-07 14:54:13 831

原创 [LeetCode]046-Permutations

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

2016-05-06 22:35:08 1299

原创 [数据结构]散列表初识

散列表也叫哈希表,是根据关键码值(Key value)而直接访问的数据结构,也就是说,它通过把关键码值映射到表中的一个位置来访问记录,以加快查找速度,这个映射函数叫散列函数,存放记录的数组叫散列表。给定表M,存在函数f(key),对任意给定的关键字值key,代入函数若能得到包含该关键字的记录在表中的地址,则称表M为哈希表,函数f(key)为哈希函数。一、基本概念1、若关键字为k,则其值存放在f(k)

2016-03-19 16:07:29 489

转载 [iOS]iOS Category

转载:http://blog.sina.com.cn/s/blog_923fdd9b0101b9da.html无论一个类设计的如何完美,都不可避免的会遇到没有预测到的需求,那怎么扩展现有的类呢?当然,继承是个不错的选择。但是Objective-C提供了一种特别的方式来扩展类,叫Catagory,可以动态的为已经存在的类添加新的行为。这样可以保证类的原原来的基础上,较小的改动就可以增加需

2016-03-03 16:54:27 361

转载 [iOS]编写高质量的Objective-C代码

本文由“海水的味道”编译点标记语法 属性和幂等方法(多次调用和一次调用返回的结果相同)使用点标记语法访问,其他的情况使用方括号标记语法。良好的风格: view.backgroundColor = [UIColor orangeColor]; [UIApplication sharedApplication].delegate;不良的风格: [view setBackgroundColor:[

2016-03-02 20:11:24 391

原创 [LeetCode]045-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 t

2015-12-30 22:47:11 404

原创 [LeetCode]044-Wildcard Matching

题目:‘?’ Matches any single character. ‘*’ Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The function prototype should

2015-12-30 21:24:25 470

原创 [LeetCode]043-Multiply Strings

题目: Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.Solution: 思路: 乘数为num1和num2,则模拟手算,每次更新nu

2015-12-30 10:38:43 340

原创 [LeetCode]042-Trapping Rain Water

题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]

2015-12-29 19:06:01 392

原创 [LeetCode]041-First Missing Positive Integer

题目: Given an unsorted integer array, find the first missing positive integer.For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant spa

2015-12-29 16:44:51 601

原创 [LeetCode]040-Combination Sum II

题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combinati

2015-12-29 14:45:05 323

原创 [LeetCode]039-Combination Sum

题目: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numbe

2015-12-29 14:18:12 336

原创 [LeetCode]038-Count And Say

题目:The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as “one 2,

2015-12-25 13:56:02 370

原创 [回溯法]八皇后问题的递归与非递归算法

八皇后的问题非常有名,初次理解可能稍有难度,不过多看书,看博客和代码,几遍下来,也基本清晰。首先不用想初始的情况,先假设前面已经排列好了几个皇后,即将排列下一个皇后。依次遍历八个位置,然后与之前的进行判断这个位置是否可行,如可行则进行下一个皇后,否则则移动位置继续判断。很简单。但是有两个个问题:1、不全,某个位置有八种方法排列,你只用了一种,当然你可以每个位置遍历,但太耗时,回溯法可以解决很大的一部

2015-12-20 14:02:45 3578 2

原创 [LeetCode]037-Sudoku Solver

题目: Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character ‘.’.You may assume that there will be only one unique solution. Solution: 思路,类似于回溯法,

2015-12-19 22:03:41 541

原创 [LeetCode]036-Valid Sudoku

题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’. Solution: (1)同一行没有相同的数字。

2015-12-16 10:06:48 526

原创 [LeetCode]035-Search Insert Position

题目: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.

2015-12-15 20:02:24 305

原创 [LeetCode]034-Search For A Range

题目: Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If the target is not found in t

2015-12-15 19:34:39 273

原创 [LeetCode]033-Search In Rotated Sorted Array

题目: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its

2015-12-15 18:56:03 231

原创 [LeetCode]032-Longest Valid Parentheses

题目: Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.For “(()”, the longest valid parentheses substring is “()”, whic

2015-12-15 13:59:13 240

原创 [LeetCode]031-Next Permutation

题目: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possibl

2015-12-14 22:47:44 247

原创 [算法]全排列计算

学过排列组合的应该都清楚什么是全排列。但是如何通过计算机编码显示一列数字所有的全排列呢?本文提出了两个方法。1、递归实现 比较“123”,思考它的全排列,无非就是数字之间的对换,1与2对换,1与3对换,变成“213”和“321”,第一位数字就这三种情况,第二位继续开始与后面的所有数字依次对换。递归的思想。 直接看代码,可能更清晰:bool Isduplicate(string per_str,i

2015-12-14 15:10:58 607

原创 [Hiho]1015-KMP算法

题目: 输入第一行一个整数N,表示测试数据组数。接下来的N*2行,每两行表示一个测试数据。在每一个测试数据中,第一行为模式串,由不超过10^4个大写字母组成,第二行为原串,由不超过10^6个大写字母组成。其中N<=20 输出对于每一个测试数据,按照它们在输入中出现的顺序输出一行Ans,表示模式串在原串中出现的次数。 Sample Input5HAHAHAHAWQNWQNADAADA

2015-12-12 22:09:44 398

原创 [LeetCode]030-Substring with Concatenation of All Words

题目: You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly onc

2015-12-12 12:32:33 272

原创 [LeetCode]029-Divide Two Integers

题目: Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT. Solution: 这个解法很多版本,有不少没有考虑越界的情况,本代码测试通过,越界情况值得深思。int divide(int dividend, int diviso

2015-12-11 21:51:57 308

原创 [LeetCode]028-Implement strStr

题目: Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Solution: 使用了KMP算法,具体介绍在网上有诸多文章介绍,我的博客算法里有篇我的学习指南:int strStr(string haystack,string needl

2015-12-11 19:18:00 282

原创 [算法]KMP算法

这个字符串匹配的算法很著名,也很难理解。研究了半天,也算看了不少博客,基本上要讲的,要理解的,各大博客大神都已详述。我把主要几篇给我很大启迪的文章列下,也给自己往后复习留下点踪迹。1、字符串匹配的KMP算法 http://kb.cnblogs.com/page/176818/ 这篇文章,看完后很快就知道KMP算法在干什么,以及我们的核心任务是什么?2、KMP算法的Next数组详解 http://w

2015-12-11 17:10:16 245

原创 [LeetCode]027-Remove Element

题目: Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn’t matter what you leave beyond the new length. Solu

2015-12-09 13:26:23 194

原创 [LeetCode]026-Remove Duplicates from Sorted Array

题目: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with

2015-12-09 13:11:04 216

原创 [LeetCode]025-Reverse Nodes in K-Group

题目: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is

2015-12-09 11:35:56 320

原创 [LeetCode]024-Swap Nodes in Pairs

题目: Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You

2015-12-08 20:25:53 312

原创 [LeetCode]023-Merge K Sorted Lists

题目: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Solution(1): 初始做法,虽使用递归,但其实还是两两合并,算法设计的比较差。超时。 复杂度为O(n^2);ListNode* mergeKLists(vector<ListNode

2015-12-08 20:04:42 312

原创 [LeetCode]022-Generate Parentheses

题目: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:“((()))”, “(()())”, “(())()”, “()(())”, “()()()”

2015-12-08 16:03:14 332

原创 [LeetCode]021-Merge Two Sorted Lists

题目: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Subscribe to see which companies asked this questionSol

2015-12-08 15:03:46 271

原创 [LeetCode]020-Valid Parentheses

题目: Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all valid

2015-12-08 14:38:07 264

原创 [LeetCode]019-Remove Nth Node From End of List

题目: Given a linked list, remove the nth node from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked li

2015-12-08 10:39:35 281

原创 [LeetCode]018-4-Sum

题目: 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.Note:Elements in a

2015-12-07 22:28:10 583

空空如也

空空如也

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

TA关注的人

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