Permutations leetcode java】的更多相关文章

题目: 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]. 题解: 这道题就用循环递归解决子问题. 因为求所有组合,这就意味着不能重复使用元素,要用visited数组. 有因为是所有可能的组合,所以…
题目: Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions. 题解: 这道题跟NQueens的解法完全一样(具体解法参照N QueensN Queens leetcode java),只不过要求的返回值不同了..所以要记录的result稍微改一下就好了... 因为涉及到递归,result传进去引用类型(…
题目: 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]. 题解: 这道题跟Permutaitons没啥大的区别,就是结果去重. 我之前也有写过去重的两个方法: 一…
题目: Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype shoul…
Reference: http://blog.csdn.net/lbyxiafei/article/details/9375735  题目: Implement int sqrt(int x). Compute and return the square root of x. 题解: 这道题很巧妙的运用了二分查找法的特性,有序,查找pos(在这道题中pos=value),找到返回pos,找不到返回邻近值. 因为是求数x(x>=0) 的平方根, 因此,结果一定是小于等于x且大于等于0,所以用二分查…
题目: 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 font for better legibility) P A H N A P L S I I G Y I R And then read line by line: "PAHNAP…
Candy There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. Children with a higher rating get more ca…
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a palindrome. Note:Have you consider that th…
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]. Notes: recursive, in place. class Solution { public: vector<vector<int>…
这里记录一下自己刷的LeetCode题目. 有些博客用英文阐述自己的思路和收获,相当于练习一下英文的表达能力. 比较好的题目有加粗. 1. Two Sum 3. Longest Substring Without Repeating Characters 5. Longest Palindromic Substring 7. Reverse Integer 9. Palindrome Number 8. String to Integer (atoi) 溢出的处理 21. Merge Two S…