[抄题]:

Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.

Example:

  1. nums = [1, 2, 3]
  2. target = 4
  3.  
  4. The possible combination ways are:
  5. (1, 1, 1, 1)
  6. (1, 1, 2)
  7. (1, 2, 1)
  8. (1, 3)
  9. (2, 1, 1)
  10. (2, 2)
  11. (3, 1)
  12.  
  13. Note that different sequences are counted as different combinations.
  14.  
  15. Therefore the output is 7.

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

DFS的退出条件每次都要走一遍,如果是计数类就不能清0了,应该返回1

[思维问题]:

[一句话思路]:

就是用dfs一直把所有方法加上就行了

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

DFS的退出条件每次都要走一遍,如果是计数类就不能清0了,应该返回1

[复杂度]:Time complexity: O(1^n) Space complexity: O(1)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[算法思想:递归/分治/贪心]:递归

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

  1. public int combinationSum4(int[] nums, int target) {
  2. if (target == 0) {
  3. return 1;
  4. }
  5. int res = 0;
  6. for (int i = 0; i < nums.length; i++) {
  7. if (target >= nums[i]) {
  8. res += combinationSum4(nums, target - nums[i]);
  9. }
  10. }
  11. return res;
  12. }

377. Combination Sum IV 返回符合目标和的组数的更多相关文章

  1. LC 377. Combination Sum IV

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  2. [LeetCode] 377. Combination Sum IV 组合之和之四

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  3. 39. Combination Sum + 40. Combination Sum II + 216. Combination Sum III + 377. Combination Sum IV

    ▶ 给定一个数组 和一个目标值.从该数组中选出若干项(项数不定),使他们的和等于目标值. ▶ 36. 数组元素无重复 ● 代码,初版,19 ms .从底向上的动态规划,但是转移方程比较智障(将待求数分 ...

  4. [LeetCode] 377. Combination Sum IV 组合之和 IV

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  5. 【LeetCode】377. Combination Sum IV 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  6. 377. Combination Sum IV

    问题 Given an integer array with all positive numbers and no duplicates, find the number of possible c ...

  7. Leetcode 377. Combination Sum IV

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  8. 377. Combination Sum IV——DP本质:针对结果的迭代,dp[ans] <= dp[ans-i] & dp[i] 找三者关系 思考问题的维度+1,除了数据集迭代还有考虑结果

    Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...

  9. 377. Combination Sum IV 70. Climbing Stairs

    back function (return number) remember the structure class Solution { int res = 0; //List<List< ...

随机推荐

  1. Oracle 12c RAC 日志体系结构的变化

    1    说明 在11g中,查看GRID的日志,会进入$ORACLE_HOM/log. [grid@cndba.cn ~]$ cd $ORACLE_HOME/log/ [grid@cndba.cn l ...

  2. 3.Python连接数据库PyMySQL

    1.安装PyMySQL,输入命令:pip3 install PyMySQL 2.使用Navicat,创建数据库:TESTDB,表:EMPLOYEE,字段:FIRST_NAME,LAST_NAME,AG ...

  3. c# 数据库通用类DbUtility

    DbProviderType数据库类型枚举 /// <summary> /// 数据库类型枚举 /// </summary> public enum DbProviderTyp ...

  4. C#修改系统环境变量,调用批处理bat

    一.设置环境变量 public void SetPath(string pathValue) { string pathlist; pathlist = Environment.GetEnvironm ...

  5. 手动下载阿里云Nexus上的Jar包

    手动下载阿里云Nexus上的Jar包 1.1 在任意目录下创建一个文件夹,创建一个pom.xml文件,一个bat批处理脚本,如图: 1.2 DownLoad.bat文件中的内容: call mvn - ...

  6. golang回调函数的例子

    package main import "fmt" type TestStruct struct { } func (object *TestStruct) test(msg st ...

  7. java代码---indexOf()方法

    总结:indexOf(String str,int index)方法.从参数指定位置开始,如果index值超过了字符串长度,则返回-1 package com.a.b; import java.io. ...

  8. Java-Runoob:Java 异常处理

    ylbtech-Java-Runoob:Java 异常处理 1.返回顶部 1. Java 异常处理 异常是程序中的一些错误,但并不是所有的错误都是异常,并且错误有时候是可以避免的. 比如说,你的代码少 ...

  9. [转]Winform 经验集

    多线程篇: CheckForIllegalCrossThreadCalls = false; 更多示例可见: http://www.cnblogs.com/z5337/p/4030287.html i ...

  10. angula的factory service provider

    本人学了一段时间的angular的服务(factory.service.provider),有了自己的一些对于他们的见解,如果说的对,敬请赐教!!! 以后更新