diff --git a/src/Main.kt b/src/Main.kt index d199a1d..4979bc1 100644 --- a/src/Main.kt +++ b/src/Main.kt @@ -1,4 +1,4 @@ fun main() { - val t = Test763() + val t = Test560() t.test() } \ No newline at end of file diff --git a/src/Test46.kt b/src/Test46.kt deleted file mode 100644 index c7e37f1..0000000 --- a/src/Test46.kt +++ /dev/null @@ -1,8 +0,0 @@ -class Test46 { - class Solution { - fun permute(nums: IntArray): List> { - val result = arrayOf(intArrayOf()) - for (i in) - } - } -} \ No newline at end of file diff --git a/src/Test560.kt b/src/Test560.kt new file mode 100644 index 0000000..9bd56c7 --- /dev/null +++ b/src/Test560.kt @@ -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)) + } +} \ No newline at end of file