10 2014 档案
leetcode[50] N-Queens
摘要:题目:给定一个n,那么在n*n的棋盘里面放国际象棋的皇后,皇后之间互不在攻击范围。(皇后的攻击范围是她所在位置的哪一行,那一列,和她的正负1的对角线)Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such... 阅读全文
posted @ 2014-10-31 23:25 higerzhang 阅读(242) 评论(0) 推荐(0)
leetcod Pow(x, n)
摘要:题目:就是实现一个指数函数。直接用一个while一直乘以n词肯定是会超时的。自己写了用递归(而且是很挫的递归),测试了无数次,根据每个case去修改代码。终于可以AC了。不忍直视,自己写了好长,如下:class Solution {public: double pow(double x, in... 阅读全文
posted @ 2014-10-31 00:00 higerzhang 阅读(368) 评论(0) 推荐(0)
leetcode Anagrams
摘要:题目:给定一个vector,然后里面有若干个字符串的长度和组成的字母是相同的,找出这些字符串记录并返回。顾名思义,也就是抛弃单一的字符串,单一是指没有和它长度相同并且组成的字母也相同的另一个字符串。原题如下:Given an array of strings, return all groups o... 阅读全文
posted @ 2014-10-30 21:17 higerzhang 阅读(243) 评论(1) 推荐(0)
leetcode Rotate Image
摘要:题目:You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?在原址上进行将矩阵旋转90度。如... 阅读全文
posted @ 2014-10-30 17:24 higerzhang 阅读(219) 评论(0) 推荐(0)
leetcode 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 max... 阅读全文
posted @ 2014-10-30 00:33 higerzhang 阅读(339) 评论(0) 推荐(0)
leetcode Permutations II
摘要:题目:和上一题一样,就是这时候给定的数字可能有重复。做法:只要将num排好序,然后判断如果当前的值等于前一个的话,那么就跳过,就不会有重复的人。果然是AC了。 1 class Solution { 2 public: 3 vector > permuteUnique(vector &num)... 阅读全文
posted @ 2014-10-29 00:25 higerzhang 阅读(265) 评论(0) 推荐(0)
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],... 阅读全文
posted @ 2014-10-29 00:05 higerzhang 阅读(314) 评论(0) 推荐(0)
leetcode 第43题 Wildcard Matching
摘要:题目:(这题好难。题目意思类似于第十题,只是这里的*就是可以匹配任意长度串,也就是第十题的‘.*’)'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequenc... 阅读全文
posted @ 2014-10-28 22:31 higerzhang 阅读(378) 评论(0) 推荐(0)
leetcode 第42题 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-n... 阅读全文
posted @ 2014-10-27 23:12 higerzhang 阅读(256) 评论(0) 推荐(0)
leetcode 第41题 Trapping Rain Water
摘要:题目:Givennnon-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... 阅读全文
posted @ 2014-10-27 00:05 higerzhang 阅读(317) 评论(0) 推荐(0)
leetcode第40题--First Missing Positive
摘要:题目:Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should... 阅读全文
posted @ 2014-10-26 22:05 higerzhang 阅读(226) 评论(0) 推荐(0)
leetcode第39题--Combination Sum II
摘要:题目:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each numb... 阅读全文
posted @ 2014-10-26 01:56 higerzhang 阅读(491) 评论(0) 推荐(0)
leetcode第38题--Combination Sum
摘要:题目:Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesamerepeated ... 阅读全文
posted @ 2014-10-25 22:23 higerzhang 阅读(351) 评论(0) 推荐(0)
leetcode第37题--Count and Say
摘要:题目:(据说是facebook的面试题哦)The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or1... 阅读全文
posted @ 2014-10-25 16:30 higerzhang 阅读(1693) 评论(0) 推荐(0)
leetcode第36题--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... 阅读全文
posted @ 2014-10-24 23:44 higerzhang 阅读(248) 评论(0) 推荐(0)
leetcode第35题--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 wi... 阅读全文
posted @ 2014-10-24 12:21 higerzhang 阅读(350) 评论(0) 推荐(0)
leetcode 34 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 or... 阅读全文
posted @ 2014-10-23 23:28 higerzhang 阅读(203) 评论(0) 推荐(0)
leetcode第33题--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 ord... 阅读全文
posted @ 2014-10-23 21:53 higerzhang 阅读(570) 评论(0) 推荐(0)
leetcode第32题--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 7might become4 5 6 7 0 1 2).You are given a target value t... 阅读全文
posted @ 2014-10-23 20:07 higerzhang 阅读(475) 评论(1) 推荐(0)
leetcode第31题--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... 阅读全文
posted @ 2014-10-22 23:11 higerzhang 阅读(272) 评论(0) 推荐(0)
leetcode第30题--Next Permutation
摘要:problem:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not... 阅读全文
posted @ 2014-10-22 00:28 higerzhang 阅读(221) 评论(0) 推荐(0)
leetcode第29题--Substring with Concatenation of All Words
摘要:problem:You are given a string,S, and a list of words,L, that are all of the same length. Find all starting indices of substring(s) in S that is a con... 阅读全文
posted @ 2014-10-21 23:19 higerzhang 阅读(340) 评论(0) 推荐(0)
leetcode第28题--Divide Two Integers
摘要:Divide two integers without using multiplication, division and mod operator.分析:题目意思很容易理解,就是不用乘除法和模运算求来做除法,很容易想到的一个方法是一直做减法,然后计数,超时。在网上找到一种解法,利用位运算,意思是... 阅读全文
posted @ 2014-10-21 00:51 higerzhang 阅读(288) 评论(0) 推荐(0)
leetcode第27题--Implement strStr()
摘要:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, ornullif needle is not part of haystack.就是判断haystack中是否有needle,如果包... 阅读全文
posted @ 2014-10-21 00:09 higerzhang 阅读(268) 评论(0) 推荐(0)
leetcode第26题--Remove Duplicates from Sorted Array
摘要:problem: Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra sp... 阅读全文
posted @ 2014-10-20 21:03 higerzhang 阅读(246) 评论(0) 推荐(0)
leetcode第25题--Remove Element
摘要:problem: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 doe... 阅读全文
posted @ 2014-10-20 17:50 higerzhang 阅读(278) 评论(0) 推荐(0)
leetcode第24题--Reverse Nodes in k-Group
摘要:problem:Given a linked list, reverse the nodes of a linked listkat a time and return its modified list.If the number of nodes is not a multiple ofkthe... 阅读全文
posted @ 2014-10-20 17:18 higerzhang 阅读(342) 评论(0) 推荐(0)
leetcode第23题--Swap Nodes in Pairs
摘要:Problem:Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Yo... 阅读全文
posted @ 2014-10-20 12:08 higerzhang 阅读(344) 评论(0) 推荐(0)
leetcode第22题--Merge k Sorted Lists
摘要:problem:Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.先合并两个list,再根据归并排序的方法递归合并。假设总共有k个list,每个list的最大... 阅读全文
posted @ 2014-10-20 00:56 higerzhang 阅读(183) 评论(0) 推荐(0)
leetcode第21题--Generate Parentheses
摘要:problem:Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is... 阅读全文
posted @ 2014-10-19 23:46 higerzhang 阅读(191) 评论(0) 推荐(0)
leetcode第20题--Valid Parentheses
摘要:Problem:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the ... 阅读全文
posted @ 2014-10-19 00:19 higerzhang 阅读(204) 评论(0) 推荐(0)
leetcode第19题--Remove Nth Node From End of List
摘要:Problem:Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. ... 阅读全文
posted @ 2014-10-18 23:45 higerzhang 阅读(215) 评论(0) 推荐(0)
leetcode第18题--Letter Combinations of a Phone Number
摘要:Problem:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the ... 阅读全文
posted @ 2014-10-18 23:26 higerzhang 阅读(189) 评论(0) 推荐(0)
leetcode第17题--4Sum
摘要:Problem:Given an arraySofnintegers, are there elementsa,b,c, anddinSsuch thata+b+c+d= target? Find all unique quadruplets in the array which gives the... 阅读全文
posted @ 2014-10-17 21:03 higerzhang 阅读(262) 评论(0) 推荐(0)
leetcode第16题--3Sum Closest
摘要:Problem:Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integer... 阅读全文
posted @ 2014-10-17 12:29 higerzhang 阅读(321) 评论(0) 推荐(0)
leetcode第15题--3Sum
摘要:Problem:Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Not... 阅读全文
posted @ 2014-10-16 22:41 higerzhang 阅读(341) 评论(0) 推荐(0)
leetcode第14题--Longest Common Prefix
摘要:Problems:Write a function to find the longest common prefix string amongst an array of strings.就是返回一个字符串数组的所有的公共前缀。不难。我是已第一个字符串为参考,然后依次遍历其他的字符串,一旦遇到不同... 阅读全文
posted @ 2014-10-16 00:07 higerzhang 阅读(205) 评论(0) 推荐(0)
leetcode第13题--Roman to Integer
摘要:Problem:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.遍历一次输入的字符串,如果不满足类似4或者9的就直接加相应的数,否则减去... 阅读全文
posted @ 2014-10-16 00:00 higerzhang 阅读(229) 评论(0) 推荐(0)
leetcode第12题--Integer to Roman
摘要:Problem:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.把阿拉伯数字转换为罗马数字输出。百度一下对应的 I V X L C D ... 阅读全文
posted @ 2014-10-15 00:53 higerzhang 阅读(317) 评论(0) 推荐(0)
leetcode第11题--Container With Most Water
摘要:Problem:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpo... 阅读全文
posted @ 2014-10-15 00:07 higerzhang 阅读(477) 评论(0) 推荐(0)
leetcode第十题--Regular Expression Matching
摘要:Problem:Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the precedin... 阅读全文
posted @ 2014-10-14 00:30 higerzhang 阅读(480) 评论(0) 推荐(0)
leetcode第九题--Palindrome Number
摘要:Problem:Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindr... 阅读全文
posted @ 2014-10-13 10:08 higerzhang 阅读(240) 评论(0) 推荐(0)
leetcode第八题--String to Integer (atoi)
摘要:Problem:Implementatoito convert a string to an integer.Hint:Carefully consider all possible input cases. If you want a challenge, please do not see be... 阅读全文
posted @ 2014-10-13 00:15 higerzhang 阅读(309) 评论(1) 推荐(0)
leetcode第七题--Reverse Integer
摘要:Problem:Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321终于什么都没参考就一次Accept了。可能是这题比较简单,同时自己也进步了一点点,leetcode就是这样给我... 阅读全文
posted @ 2014-10-12 21:02 higerzhang 阅读(360) 评论(1) 推荐(0)
leetcode第六题--ZigZag Conversion
摘要:Problem: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... 阅读全文
posted @ 2014-10-11 23:29 higerzhang 阅读(380) 评论(0) 推荐(0)
leetcode第五题--Longest Palindromic Substring
摘要:Problem:Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique lo... 阅读全文
posted @ 2014-10-10 23:49 higerzhang 阅读(328) 评论(0) 推荐(0)
leetcode第四题--Add Two Numbers
摘要:Problem:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a... 阅读全文
posted @ 2014-10-09 23:44 higerzhang 阅读(252) 评论(0) 推荐(0)
leetcode第三题--Longest Substring Without Repeating Characters
摘要:Problem:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating le... 阅读全文
posted @ 2014-10-08 23:51 higerzhang 阅读(452) 评论(0) 推荐(0)
leetcode第二题--Median of Two Sorted Arrays
摘要:Problem:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity sh... 阅读全文
posted @ 2014-10-07 23:10 higerzhang 阅读(441) 评论(0) 推荐(0)