Skip to content

Commit 5741364

Browse files
committed
feat: add kotlin solution to lc problem: No.0713
1 parent 2903335 commit 5741364

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

solution/0700-0799/0713.Subarray Product Less Than K/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,26 @@ var numSubarrayProductLessThanK = function (nums, k) {
205205
};
206206
```
207207

208+
#### Kotlin
209+
210+
```kotlin
211+
class Solution {
212+
fun numSubarrayProductLessThanK(nums: IntArray, k: Int): Int {
213+
var left = 0
214+
var count = 0
215+
var product = 1
216+
nums.forEachIndexed { right, num ->
217+
product *= num
218+
while (product >= k && left <= right) {
219+
product /= nums[left++]
220+
}
221+
count += right - left + 1
222+
}
223+
return count
224+
}
225+
}
226+
```
227+
208228
<!-- tabs:end -->
209229

210230
<!-- solution:end -->

solution/0700-0799/0713.Subarray Product Less Than K/README_EN.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,26 @@ var numSubarrayProductLessThanK = function (nums, k) {
186186
};
187187
```
188188

189+
#### Kotlin
190+
191+
```kotlin
192+
class Solution {
193+
fun numSubarrayProductLessThanK(nums: IntArray, k: Int): Int {
194+
var left = 0
195+
var count = 0
196+
var product = 1
197+
nums.forEachIndexed { right, num ->
198+
product *= num
199+
while (product >= k && left <= right) {
200+
product /= nums[left++]
201+
}
202+
count += right - left + 1
203+
}
204+
return count
205+
}
206+
}
207+
```
208+
189209
<!-- tabs:end -->
190210

191211
<!-- solution:end -->
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
fun numSubarrayProductLessThanK(nums: IntArray, k: Int): Int {
3+
var left = 0
4+
var count = 0
5+
var product = 1
6+
nums.forEachIndexed { right, num ->
7+
product *= num
8+
while (product >= k && left <= right) {
9+
product /= nums[left++]
10+
}
11+
count += right - left + 1
12+
}
13+
return count
14+
}
15+
}

0 commit comments

Comments
 (0)