78. Subsets

  1. Given a set of distinct integers, nums, return all possible subsets.
  2.  
  3. Note: The solution set must not contain duplicate subsets.
  4.  
  5. For example,
  6. If nums = [,,], a solution is:
  7.  
  8. [
  9. [],
  10. [],
  11. [],
  12. [,,],
  13. [,],
  14. [,],
  15. [,],
  16. []
  17. ]
  1. class Solution
  2. {
  3. public:
  4. vector<vector<int>> subsets(vector<int>& nums)
  5. {
  6. const size_t n = nums.size();
  7. vector<int> v;
  8. vector<vector<int> > result;
  9. for (int i = ; i < <<n; ++i)
  10. {
  11. for (int j = ; j < n; ++j)
  12. {
  13. if(i & << j) v.push_back(nums[j]);
  14. }
  15. result.push_back(v);
  16. v.clear();
  17. }
  18. return result;
  19. }
  20. };

3ms

迭代,增量构造.没看懂

http://www.cnblogs.com/TenosDoIt/p/3451902.html

  1. class Solution {
  2. public:
  3. vector<vector<int> > subsets(vector<int> &S) {
  4. sort(S.begin(), S.end());
  5. vector<vector<int> > result();
  6. for (auto elem : S) {
  7. result.reserve(result.size() * );
  8. auto half = result.begin() + result.size();
  9. copy(result.begin(), half, back_inserter(result));
  10. for_each(half, result.end(), [&elem](decltype(result[]) &e){
  11. e.push_back(elem);
  12. });
  13. }
  14. return result;
  15. }
  16. };

3ms

位向量法

  1. class Solution {
  2. public:
  3. vector<vector<int> > subsets(vector<int> &S) {
  4. sort(S.begin(), S.end()); //
  5. vector<vector<int> > result;
  6. vector<bool> selected(S.size(), false);
  7. subsets(S, selected, , result);
  8. return result;
  9. }
  10. private:
  11. static void subsets(const vector<int> &S, vector<bool> &selected, int step,
  12. vector<vector<int> > &result) {
  13. if (step == S.size()) {
  14. vector<int> subset;
  15. for (int i = ; i < S.size(); i++) {
  16. if (selected[i]) subset.push_back(S[i]);
  17. }
  18. result.push_back(subset);
  19. return;
  20. }
  21. //S[step]
  22. selected[step] = false;
  23. subsets(S, selected, step + , result);
  24. //S[step]
  25. selected[step] = true;
  26. subsets(S, selected, step + , result);
  27. }
  28. };

6ms

  1. class Solution {
  2. public:
  3. vector<vector<int> > subsets(vector<int> &S) {
  4. sort(S.begin(), S.end()); //
  5. vector<vector<int> > result;
  6. vector<int> path;
  7. subsets(S, path, , result);
  8. return result;
  9. }
  10. private:
  11. static void subsets(const vector<int> &S, vector<int> &path, int step,
  12. vector<vector<int> > &result) {
  13. if (step == S.size()) {
  14. result.push_back(path);
  15. return;
  16. }
  17. //S[step]
  18. subsets(S, path, step + , result);
  19. //S[step]
  20. path.push_back(S[step]);
  21. subsets(S, path, step + , result);
  22. path.pop_back();
  23. }
  24. };

6ms

解题思路

  1. Iterative
  2.  
  3. This problem can also be solved iteratively. Take [, , ] in the problem statement as an example. The process of generating all the subsets is like:
  4.  
  5. Initially: [[]]
  6. Adding the first number to all the existed subsets: [[], []];
  7. Adding the second number to all the existed subsets: [[], [], [], [, ]];
  8. Adding the third number to all the existed subsets: [[], [], [], [, ], [], [, ], [, ], [, , ]].
  9. Have you got the idea :-)
  10.  
  11. The code is as follows.
  12.  
  13. class Solution {
  14. public:
  15. vector<vector<int>> subsets(vector<int>& nums) {
  16. sort(nums.begin(), nums.end());
  17. vector<vector<int>> subs(, vector<int>());
  18. for (int i = ; i < nums.size(); i++) {
  19. int n = subs.size();
  20. for (int j = ; j < n; j++) {
  21. subs.push_back(subs[j]);
  22. subs.back().push_back(nums[i]);
  23. }
  24. }
  25. return subs;
  26. }
  27. };

  1. // Recursion.
  2. class Solution {
  3. public:
  4. vector<vector<int> > subsets(vector<int> &S) {
  5. vector<vector<int> > res;
  6. vector<int> out;
  7. sort(S.begin(), S.end());
  8. getSubsets(S, , out, res);
  9. return res;
  10. }
  11. void getSubsets(vector<int> &S, int pos, vector<int> &out, vector<vector<int> > &res) {
  12. res.push_back(out);
  13. for (int i = pos; i < S.size(); ++i) {
  14. //if (i != pos && S[i] == S[i-1]) continue;//subsets II
  15. out.push_back(S[i]);
  16. getSubsets(S, i + , out, res);
  17. out.pop_back();
  18. //while (S[i] == S[i + 1]) ++i; //subsets II
  19. }
  20. }
  21. };

  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. class Solution {
  6. public:
  7. vector<vector<int> > subsetsWithDup(vector<int> &S) {
  8. sort(S.begin(), S.end()); // ????
  9. vector<vector<int> > result;
  10. vector<int> path;
  11. dfs(S, S.begin(), path, result);
  12. for (int i = ; i < result.size(); ++i) {
  13. for (int j = ; j < result[i].size(); ++j) {
  14. printf("%d ", result[i][j]);
  15. }printf("\n");
  16. }
  17. return result;
  18. }
  19. private:
  20. static void dfs(const vector<int> &S, vector<int>::iterator start,
  21. vector<int> &path, vector<vector<int> > &result) {
  22. result.push_back(path);
  23. printf("@@@@@@@@@@Line:%d start:%d\n", __LINE__, *start);
  24. for (auto i = start; i < S.end(); i++) {
  25. printf("i:%d\n", *i);
  26. if (i != start && *i == *(i-))
  27. {
  28. printf("Continue****LINE:%d start:%d i:%d\n", __LINE__, *start, *i);
  29. continue;
  30. }
  31. path.push_back(*i);
  32. dfs(S, i + , path, result); for(auto xx : path) printf("BEFORE:%d ", xx);
  33. printf("\nLINE:%d start:%d i:%d\n", __LINE__, *start, *i);
  34. path.pop_back(); for (auto xx : path) printf("AFTER:%d ", xx); printf("\n");
  35. }
  36. }
  37. };
  38.  
  39. int main(int argc, char *argv[])
  40. {
  41. vector<int> v{,,};
  42. Solution sn;
  43. sn.subsetsWithDup(v);
  44. //printf("%d %d\n",v[0],v.size());
  45. return ;
  46. }

同类回溯算法问题归纳: by issac3

This structure might apply to many other backtracking questions, but here I am just going to demonstrate Subsets, Permutations, and Combination Sum.

Subsets : https://leetcode.com/problems/subsets/

  1. public List<List<Integer>> subsets(int[] nums) {
  2. List<List<Integer>> list = new ArrayList<>();
  3. Arrays.sort(nums);
  4. backtrack(list, new ArrayList<>(), nums, );
  5. return list;
  6. }
  7.  
  8. private void backtrack(List<List<Integer>> list , List<Integer> tempList, int [] nums, int start){
  9. list.add(new ArrayList<>(tempList));
  10. for(int i = start; i < nums.length; i++){
  11. tempList.add(nums[i]);
  12. backtrack(list, tempList, nums, i + );
  13. tempList.remove(tempList.size() - );
  14. }
  15. }

Subsets II (contains duplicates) : https://leetcode.com/problems/subsets-ii/

  1. public List<List<Integer>> subsetsWithDup(int[] nums) {
  2. List<List<Integer>> list = new ArrayList<>();
  3. Arrays.sort(nums);
  4. backtrack(list, new ArrayList<>(), nums, );
  5. return list;
  6. }
  7.  
  8. private void backtrack(List<List<Integer>> list, List<Integer> tempList, int [] nums, int start){
  9. list.add(new ArrayList<>(tempList));
  10. for(int i = start; i < nums.length; i++){
  11. if(i > start && nums[i] == nums[i-]) continue; // skip duplicates
  12. tempList.add(nums[i]);
  13. backtrack(list, tempList, nums, i + );
  14. tempList.remove(tempList.size() - );
  15. }
  16. }

Permutations : https://leetcode.com/problems/permutations/

  1. public List<List<Integer>> permute(int[] nums) {
  2. List<List<Integer>> list = new ArrayList<>();
  3. // Arrays.sort(nums); // not necessary
  4. backtrack(list, new ArrayList<>(), nums);
  5. return list;
  6. }
  7.  
  8. private void backtrack(List<List<Integer>> list, List<Integer> tempList, int [] nums){
  9. if(tempList.size() == nums.length){
  10. list.add(new ArrayList<>(tempList));
  11. } else{
  12. for(int i = ; i < nums.length; i++){
  13. if(tempList.contains(nums[i])) continue; // element already exists, skip
  14. tempList.add(nums[i]);
  15. backtrack(list, tempList, nums);
  16. tempList.remove(tempList.size() - );
  17. }
  18. }
  19. }

Permutations II (contains duplicates) : https://leetcode.com/problems/permutations-ii/

  1. public List<List<Integer>> permuteUnique(int[] nums) {
  2. List<List<Integer>> list = new ArrayList<>();
  3. Arrays.sort(nums);
  4. backtrack(list, new ArrayList<>(), nums, new boolean[nums.length]);
  5. return list;
  6. }
  7.  
  8. private void backtrack(List<List<Integer>> list, List<Integer> tempList, int [] nums, boolean [] used){
  9. if(tempList.size() == nums.length){
  10. list.add(new ArrayList<>(tempList));
  11. } else{
  12. for(int i = ; i < nums.length; i++){
  13. if(used[i] || i > && nums[i] == nums[i-] && !used[i - ]) continue;
  14. used[i] = true;
  15. tempList.add(nums[i]);
  16. backtrack(list, tempList, nums, used);
  17. used[i] = false;
  18. tempList.remove(tempList.size() - );
  19. }
  20. }
  21. }

Combination Sum : https://leetcode.com/problems/combination-sum/

  1. public List<List<Integer>> combinationSum(int[] nums, int target) {
  2. List<List<Integer>> list = new ArrayList<>();
  3. Arrays.sort(nums);
  4. backtrack(list, new ArrayList<>(), nums, target, );
  5. return list;
  6. }
  7.  
  8. private void backtrack(List<List<Integer>> list, List<Integer> tempList, int [] nums, int remain, int start){
  9. if(remain < ) return;
  10. else if(remain == ) list.add(new ArrayList<>(tempList));
  11. else{
  12. for(int i = start; i < nums.length; i++){
  13. tempList.add(nums[i]);
  14. backtrack(list, tempList, nums, remain - nums[i], i); // not i + 1 because we can reuse same elements
  15. tempList.remove(tempList.size() - );
  16. }
  17. }
  18. }

Combination Sum II (can't reuse same element) : https://leetcode.com/problems/combination-sum-ii/

  1. public List<List<Integer>> combinationSum2(int[] nums, int target) {
  2. List<List<Integer>> list = new ArrayList<>();
  3. Arrays.sort(nums);
  4. backtrack(list, new ArrayList<>(), nums, target, );
  5. return list;
  6.  
  7. }
  8.  
  9. private void backtrack(List<List<Integer>> list, List<Integer> tempList, int [] nums, int remain, int start){
  10. if(remain < ) return;
  11. else if(remain == ) list.add(new ArrayList<>(tempList));
  12. else{
  13. for(int i = start; i < nums.length; i++){
  14. if(i > start && nums[i] == nums[i-]) continue; // skip duplicates
  15. tempList.add(nums[i]);
  16. backtrack(list, tempList, nums, remain - nums[i], i + );
  17. tempList.remove(tempList.size() - );
  18. }
  19. }
  20. }

Palindrome Partitioning : https://leetcode.com/problems/palindrome-partitioning/

  1. public List<List<String>> partition(String s) {
  2. List<List<String>> list = new ArrayList<>();
  3. backtrack(list, new ArrayList<>(), s, );
  4. return list;
  5. }
  6.  
  7. public void backtrack(List<List<String>> list, List<String> tempList, String s, int start){
  8. if(start == s.length())
  9. list.add(new ArrayList<>(tempList));
  10. else{
  11. for(int i = start; i < s.length(); i++){
  12. if(isPalindrome(s, start, i)){
  13. tempList.add(s.substring(start, i + ));
  14. backtrack(list, tempList, s, i + );
  15. tempList.remove(tempList.size() - );
  16. }
  17. }
  18. }
  19. }
  20.  
  21. public boolean isPalindrome(String s, int low, int high){
  22. while(low < high)
  23. if(s.charAt(low++) != s.charAt(high--)) return false;
  24. return true;
  25. }
  1. /*Without any crap! Hit the road!
  2.  
  3. Since we have to collect all the possible sets that meet the requirements -> a palindrome; so traversing the whole possible paths will be definitely the case -> using DFS and backtracking seems to be on the table.
  4.  
  5. try from the start index of the string till any index latter and then check its validity - a palindrome? from the start index till the ending?
  6. if so, we need to store it in a stack for latter collection and then traverse further starting from the previous ending index exclusively and begin the checking again and on and on till the start index is beyond the string;
  7. at that time we are to collect the palindromes along the paths.
  8. Several stuff should be specified:
  9.  
  10. checking whether a string is palindrome is quite simple in C using pointer;
  11. using DP might not help a lot since the checking process is quite fast while DP will require extra work to record and space allocation and so on.
  12. In the end, let's check its space and time consumption:
  13.  
  14. space cost O(n*2^n) -> one set of palindrome will take about O(n) but the amount of sets is dependent on the original string itself.
  15. time cost O(n*2^n) -> collecting them while using the space to store them so the space and time cost should be linearly proportional; since the range can be varied a lot depending on the actual provided string so the performance might not be a problem. by LHearen
    4ms in us. 72ms in cn.
  16. */
  17.  
  18. void traverse(char* s, int len, int begin, char** stack, int top, char**** arrs, int** colSizes, int* returnSize)
  19. {
  20. if(begin == len) //there is nothing left, collect the strings of a set;
  21. {
  22. *returnSize += ;
  23. *colSizes = (int*)realloc(*colSizes, sizeof(int)*(*returnSize));
  24. int size = top+;
  25. (*colSizes)[*returnSize-] = size;
  26. *arrs = (char***)realloc(*arrs, sizeof(char**)*(*returnSize));
  27. (*arrs)[*returnSize-] = (char**)malloc(sizeof(char*)*size);
  28. for(int i = ; i < size; i++)
  29. (*arrs)[*returnSize-][i] = stack[i];
  30. return ;
  31. }
  32. for(int i = begin; i < len; i++) //check each string that begin with s[begin];
  33. {
  34. int l=begin, r=i;
  35. while(l<r && s[l]==s[r]) l++, r--;
  36. if(l >= r) //it's a palindrome;
  37. {
  38. int size = i-begin+;
  39. char *t = (char*)malloc(sizeof(char)*(size+));
  40. *t = '\0';
  41. strncat(t, s+begin, size);
  42. stack[top+] = t;
  43. traverse(s, len, i+, stack, top+, arrs, colSizes, returnSize); //collect the left;
  44. }
  45. }
  46. }
  47.  
  48. char*** partition(char* s, int** colSizes, int* returnSize)
  49. {
  50. if(!*s) return NULL;
  51. int len = strlen(s);
  52. *returnSize = ;
  53. *colSizes = (char*)malloc(sizeof(char));
  54. char*** arrs = (char***)malloc(sizeof(char**));
  55. char** stack = (char**)malloc(sizeof(char*)*len);
  56. int top = -;
  57. traverse(s, strlen(s), , stack, top, &arrs, colSizes, returnSize);
  58. return arrs;
  59. }
  1. public class Solution {
  2. public List<List<String>> partition(String s) {
  3. List<List<String>> res = new ArrayList<>();
  4. boolean[][] dp = new boolean[s.length()][s.length()];
  5. for(int i = 0; i < s.length(); i++) {
  6. for(int j = 0; j <= i; j++) {
  7. if(s.charAt(i) == s.charAt(j) && (i - j <= 2 || dp[j+1][i-1])) {
  8. dp[j][i] = true;
  9. }
  10. }
  11. }
  12. helper(res, new ArrayList<>(), dp, s, 0);
  13. return res;
  14. }
  15.  
  16. private void helper(List<List<String>> res, List<String> path, boolean[][] dp, String s, int pos) {
  17. if(pos == s.length()) {
  18. res.add(new ArrayList<>(path));
  19. return;
  20. }
  21.  
  22. for(int i = pos; i < s.length(); i++) {
  23. if(dp[pos][i]) {
  24. path.add(s.substring(pos,i+1));
  25. helper(res, path, dp, s, i+1);
  26. path.remove(path.size()-1);
  27. }
  28. }
  29. }
  30. }
  31.  
  32. /*
  33. The normal dfs backtracking will need to check each substring for palindrome, but a dp array can be used to record the possible break for palindrome before we start recursion.
  34.  
  35. Edit:
  36. Sharing my thought process:
  37. first, I ask myself that how to check if a string is palindrome or not, usually a two point solution scanning from front and back. Here if you want to get all the possible palindrome partition, first a nested for loop to get every possible partitions for a string, then a scanning for all the partitions. That's a O(n^2) for partition and O(n^2) for the scanning of string, totaling at O(n^4) just for the partition. However, if we use a 2d array to keep track of any string we have scanned so far, with an addition pair, we can determine whether it's palindrome or not by justing looking at that pair, which is this line if(s.charAt(i) == s.charAt(j) && (i - j <= 2 || dp[j+1][i-1])). This way, the 2d array dp contains the possible palindrome partition among all.
  38.  
  39. second, based on the prescanned palindrome partitions saved in dp array, a simple backtrack does the job. Java DP + DFS solution by yfcheng
  40. */
  1. bool isPalin(char* s, int end);
  2. void helper(char* s, char*** ret, int** colS, int* retS, char** cur, int k );
  3.  
  4. char*** partition(char* s, int** colS, int* retS)
  5. {
  6. *retS = ;
  7. if(s == NULL || !strcmp(s, "")) return NULL;
  8.  
  9. /* I know ... I hate static mem alloc as well */
  10. *colS = (int*)malloc(sizeof(int)*);
  11. char*** ret = (char***)malloc(sizeof(char**) * );
  12. int len = strlen(s)+;
  13.  
  14. char** cur = (char**)malloc(sizeof(char*) * );
  15. for(int i = ; i<; i++)
  16. cur[i] = (char*)malloc(len);
  17.  
  18. /* backtracking starting from s[0] */
  19. helper(s, ret, colS, retS, cur, );
  20.  
  21. return ret;
  22. }
  23.  
  24. void helper(char* s, char*** ret, int** colS, int* retS, char** cur, int k )
  25. {
  26. /* termination if already at the end of string s
  27. we found a partition */
  28. if(*s == )
  29. {
  30. ret[*retS] = (char**)malloc(sizeof(char*)*k);
  31. for(int i = ; i<k; i++)
  32. {
  33. ret[*retS][i] = (char*)malloc(strlen(cur[i]) + );
  34. strcpy(ret[*retS][i], cur[i]);
  35. }
  36. (*colS)[(*retS)++] = k;
  37. return;
  38. }
  39.  
  40. /* explore next */
  41. int len = strlen(s);
  42. for(int i = ; i < len; i++)
  43. {
  44. if(isPalin(s, i))
  45. {
  46. /* put it into the cur list */
  47. strncpy(cur[k], s, i+);
  48. cur[k][i+] = '\0';
  49.  
  50. /* backtracking */
  51. helper(s+i+, ret, colS, retS, cur, k+);
  52. }
  53. }
  54. }
  55.  
  56. bool isPalin(char* s, int end)
  57. {
  58. /* printf("error: start %d, end %d\n", start, end); */
  59. if(end < ) return false;
  60. int start = ;
  61. while(end > start)
  62. {
  63. if(s[start] != s[end]) return false;
  64. start++; end--;
  65. }
  66. return true;
  67. }
  68.  
  69. // by zcjsword Created at: September 11, 2015 5:12 AM
  1. char*** result;
  2. int head;
  3.  
  4. int check(char* s,int left,int right){
  5. while(s[left]==s[right]){
  6. left++,right--;
  7. }
  8. return left>=right;
  9. }
  10.  
  11. int getResult(char* s,int left,int right,int path[],int index,int* colSize){
  12. //printf("%d %d\n",left,right);
  13. if(left>right){
  14. char** list=(char**)malloc(sizeof(char*));
  15. int h=;
  16.  
  17. for(int i=index-;i>;i--){
  18. char* tmp=(char*)malloc(sizeof(char)*(path[i-]-path[i]+));
  19. int count=;
  20. for(int j=path[i];j<path[i-];j++){
  21. tmp[count++]=s[j];
  22. }
  23. tmp[count]='\0';
  24. list[h++]=tmp;
  25. list=(char**)realloc(list,sizeof(char*)*(h+));
  26. }
  27. colSize[head]=h;
  28. result[head++]=list;
  29. result=(char***)realloc(result,sizeof(char**)*(head+));
  30.  
  31. }
  32. for(int i=right;i>=left;i--){
  33. if(check(s,i,right)){
  34. path[index]=i;
  35. getResult(s,left,i-,path,index+,colSize);
  36. }
  37. }
  38. return ;
  39. }
  40.  
  41. char*** partition(char* s, int** columnSizes, int* returnSize) {
  42. result=(char***)malloc(sizeof(char**));
  43. head=;
  44. int path[];
  45. *columnSizes=(int*)malloc(sizeof(int)*);
  46. path[]=strlen(s);
  47. getResult(s,,path[]-,path,,*columnSizes);
  48. *returnSize=head;
  49. return result;
  50. }
  51. // 28ms example
  1. #define MAXCOL 1000
  2. void DFS(char *s,int startIndex,char **temp_result,char ***result,
  3. int len,int** columnSizes, int* returnSize)
  4. {
  5. int i,j;
  6. if(startIndex >= len)
  7. {
  8. for(i = ;i < (*columnSizes)[*returnSize];i ++)
  9. {
  10. for(j = ;temp_result[i][j] != '\0';j ++)
  11. {
  12. result[*returnSize][i][j] = temp_result[i][j];
  13. }
  14. result[*returnSize][i][j] = '\0';
  15. }
  16. *returnSize += ;
  17. (*columnSizes)[*returnSize] = (*columnSizes)[*returnSize-];
  18. }
  19. for(i = startIndex;i < len;i ++)
  20. {
  21. int left = startIndex;
  22. int right = i;
  23. while(left <= right && s[left]==s[right])
  24. {
  25. left ++;
  26. right --;
  27. }
  28. if(left >= right)
  29. {
  30. strncpy(temp_result[(*columnSizes)[*returnSize]],s+startIndex,i - startIndex + );
  31. temp_result[(*columnSizes)[*returnSize]][i - startIndex + ] = '\0';
  32. (*columnSizes)[*returnSize] += ;
  33. //printf("OK\n");
  34. DFS(s,i+,temp_result,result,len,columnSizes,returnSize);
  35. (*columnSizes)[*returnSize] -= ;
  36. }
  37. }
  38. }
  39.  
  40. char*** partition(char* s, int** columnSizes, int* returnSize) {
  41. int i,j,k;
  42. int len = strlen(s);
  43. char ***result = malloc(MAXCOL*sizeof(char**));
  44. for(i = ;i < MAXCOL;i ++)
  45. {
  46. result[i] = malloc(len*sizeof(char*));
  47. for(j = ;j < len;j ++)
  48. {
  49. result[i][j] = malloc(len*sizeof(char));
  50. }
  51. }
  52. char **temp_result = malloc(len*sizeof(char*));
  53. for(i = ;i < len;i ++)
  54. {
  55. temp_result[i] = malloc(len*sizeof(char));
  56. }
  57. *columnSizes = calloc(MAXCOL,sizeof(int));
  58. *returnSize = ;
  59. DFS(s,,temp_result,result,len,columnSizes,returnSize);
  60. return result;
  61. }
  62. // 52ms example

78. Subsets(M) & 90. Subsets II(M) & 131. Palindrome Partitioning的更多相关文章

  1. leetcode 131. Palindrome Partitioning 、132. Palindrome Partitioning II

    131. Palindrome Partitioning substr使用的是坐标值,不使用.begin()..end()这种迭代器 使用dfs,类似于subsets的题,每次判断要不要加入这个数 s ...

  2. Leetcode 22. Generate Parentheses Restore IP Addresses (*) 131. Palindrome Partitioning

    backtracking and invariant during generating the parathese righjt > left  (open bracket and cloas ...

  3. leetcode 78. Subsets 、90. Subsets II

    第一题是输入数组的数值不相同,第二题是输入数组的数值有相同的值,第二题在第一题的基础上需要过滤掉那些相同的数值. level代表的是需要进行选择的数值的位置. 78. Subsets 错误解法: cl ...

  4. 131. Palindrome Partitioning(回文子串划分 深度优先)

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  5. [LeetCode] 131. Palindrome Partitioning 回文分割

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  6. Leetcode 131. Palindrome Partitioning

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  7. 131. Palindrome Partitioning

    题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...

  8. [leetcode]131. Palindrome Partitioning字符串分割成回文子串

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  9. 【LeetCode】131. Palindrome Partitioning

    Palindrome Partitioning Given a string s, partition s such that every substring of the partition is ...

随机推荐

  1. 浅谈 iOS 中的 Activity Indicator

    Activity Indicator 是iOS开发中必不可少的一个视图.本文就简单地总结一下这个Activity Indicator 的使用方法. 默认 Activity Indicator 以下的函 ...

  2. 在Windows商店应用中使用浅色主题

    在开发商店应用时会遇到这样的情况,设计师给我们的设计是浅色背景/深色文本,而商店应用默认是深色背景/浅色文本.那我们需要在每个页面去显式声明背景色和前景色吗,这显然是不理想的.这时就需要设置应用的主题 ...

  3. Js_字体滚动换颜色

    <html><head><meta http-equiv="Content-Type" content="text/html; charse ...

  4. Daily Scrumming* 2015.12.15(Day 7)

    一.团队scrum meeting照片 二.成员工作总结 姓名 任务ID 迁入记录 江昊 任务1036 https://github.com/buaaclubs-team/temp-front/com ...

  5. pdf修复

    pdf工具下载地址: 链接:https://pan.baidu.com/s/1SgGSrH7apX64hQEl732wWg 提取码:kg5q 使用说明: 1.含注册命令,先注册再运行.

  6. linq to sql中的自动缓存(对象跟踪)

    linq to sql中,对于同一个DataContext上下文环境,根据表主键选择记录时(当然这里所指的“记录”会自动转成“对象”),如果该记录已经被select过,默认情况下会被自动缓存下来,下次 ...

  7. PowerDesigner16工具学习笔记-建立CDM

    1.基本术语 1.1.实体和属性 实体(entity):指现实世界中客观存在,并可相互区别的事物或者事件. 属性(attribute):一组用来描述实体特征的属性. 实体集(entity set):具 ...

  8. 在 IntelliJ IDEA 中配置 Spark(Java API) 运行环境

    1. 新建Maven项目 初始Maven项目完成后,初始的配置(pom.xml)如下: 2. 配置Maven 向项目里新建Spark Core库 <?xml version="1.0& ...

  9. 软件工程学习之小学四则混合运算出题软件 Version 1.00 设计思路及感想

    对于小学四则混合运算出题软件的设计,通过分析设计要求,我觉得为了这个软件在今后便于功能上的扩充,可以利用上学期所学习的<编译原理>一课中的LL1语法分析及制导翻译的算法来实现.这样做的好处 ...

  10. JAVA面对对象(一)——封装

    1.封装思想:将对象的属性和行为封装起来的载体是类,类通常对客户隐藏其实现的细节 2.封装就是将属性私有化(private),并提供公共的方法(public)访问私有属性 3.通过封装,实现对属性数据 ...