leetcode N-QueensII
摘要:题目和上一题一样,就是要求输出有多少种结果。最直接的就是,只要在上一题的代码return ans.size();就可以了。果然也是AC了。然后我翻看了几种别人写的,暂时还没有找到复杂度可以比上一题降低多少的。可以加一个全局变量。以前都没有想到给solution类加全局变量。满足条件的时候全局变量加一...
阅读全文
posted @
2014-11-01 00:02
higerzhang
阅读(201)
推荐(0)
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
阅读(227)
推荐(0)
leetcod Pow(x, n)
摘要:题目:就是实现一个指数函数。直接用一个while一直乘以n词肯定是会超时的。自己写了用递归(而且是很挫的递归),测试了无数次,根据每个case去修改代码。终于可以AC了。不忍直视,自己写了好长,如下:class Solution {public: double pow(double x, in...
阅读全文
posted @
2014-10-31 00:00
higerzhang
阅读(355)
推荐(0)
leetcode Anagrams
摘要:题目:给定一个vector,然后里面有若干个字符串的长度和组成的字母是相同的,找出这些字符串记录并返回。顾名思义,也就是抛弃单一的字符串,单一是指没有和它长度相同并且组成的字母也相同的另一个字符串。原题如下:Given an array of strings, return all groups o...
阅读全文
posted @
2014-10-30 21:17
higerzhang
阅读(227)
推荐(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
阅读(192)
推荐(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
阅读(319)
推荐(0)
leetcode Permutations II
摘要:题目:和上一题一样,就是这时候给定的数字可能有重复。做法:只要将num排好序,然后判断如果当前的值等于前一个的话,那么就跳过,就不会有重复的人。果然是AC了。 1 class Solution { 2 public: 3 vector > permuteUnique(vector &num)...
阅读全文
posted @
2014-10-29 00:25
higerzhang
阅读(250)
推荐(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
阅读(295)
推荐(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
阅读(361)
推荐(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
阅读(228)
推荐(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
阅读(291)
推荐(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
阅读(203)
推荐(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
阅读(451)
推荐(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
阅读(326)
推荐(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
阅读(1664)
推荐(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
阅读(224)
推荐(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
阅读(333)
推荐(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
阅读(187)
推荐(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
阅读(519)
推荐(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
阅读(449)
推荐(0)