0809
This commit is contained in:
parent
beebc54755
commit
a98623af75
3 changed files with 24 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
|||
fun main() {
|
||||
val t = Test763()
|
||||
val t = Test560()
|
||||
t.test()
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
class Test46 {
|
||||
class Solution {
|
||||
fun permute(nums: IntArray): List<List<Int>> {
|
||||
val result = arrayOf(intArrayOf())
|
||||
for (i in)
|
||||
}
|
||||
}
|
||||
}
|
23
src/Test560.kt
Normal file
23
src/Test560.kt
Normal file
|
@ -0,0 +1,23 @@
|
|||
class Test560 {
|
||||
class Solution {
|
||||
fun subarraySum(nums: IntArray, k: Int): Int {
|
||||
var result = 0
|
||||
for (i in nums.indices) {
|
||||
var sum = 0
|
||||
for (j in i..nums.lastIndex){
|
||||
sum += nums[j]
|
||||
if (sum == k){
|
||||
result ++
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
fun test(): Unit {
|
||||
// println(Solution().subarraySum(intArrayOf(1,1,1),2))
|
||||
// println(Solution().subarraySum(intArrayOf(1,2,3),3))
|
||||
println(Solution().subarraySum(intArrayOf(1,-1,0),0))
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue