Skip to content

Instantly share code, notes, and snippets.

@takayahilton
Created April 24, 2015 00:19
Show Gist options
  • Save takayahilton/4aa69fe801fbb0162b34 to your computer and use it in GitHub Desktop.
Save takayahilton/4aa69fe801fbb0162b34 to your computer and use it in GitHub Desktop.
listの部分和でkを満たすものが存在するかどうかを判定する
def dfs(li:List[Int] ,k:Int,sum:Int = 0):Boolean = li match{
case _ if sum == k => true
case Nil => false
case x::xs => dfs(xs,k,sum) || dfs(xs,k,sum+x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment