-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #823 from 0xff-dev/713
Add solution and test-cases for problem 713
- Loading branch information
Showing
3 changed files
with
45 additions
and
26 deletions.
There are no files selected for viewing
24 changes: 10 additions & 14 deletions
24
leetcode/701-800/0713.Subarray-Product-Less-Than-K/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 25 additions & 2 deletions
27
leetcode/701-800/0713.Subarray-Product-Less-Than-K/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,28 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
func Solution(nums []int, k int) int { | ||
cache := make(map[int]int) | ||
ans := 0 | ||
if nums[0] < k { | ||
cache[nums[0]] = 1 | ||
ans++ | ||
} | ||
for i := 1; i < len(nums); i++ { | ||
if nums[i] >= k { | ||
cache = map[int]int{} | ||
continue | ||
} | ||
next := map[int]int{nums[i]: 1} | ||
for kk, v := range cache { | ||
if r := nums[i] * kk; r < k { | ||
next[r] += v | ||
} | ||
} | ||
cache = next | ||
for _, v := range cache { | ||
ans += v | ||
} | ||
} | ||
|
||
return ans | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters