From 31adfc6ec38bde08d3b701d1f4317e737d4835e1 Mon Sep 17 00:00:00 2001 From: keineahnung2345 Date: Mon, 18 Apr 2022 21:12:37 +0800 Subject: [PATCH] Update 713. Subarray Product Less Than K.cpp --- 713. Subarray Product Less Than K.cpp | 38 ++++++++++++++++++++------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/713. Subarray Product Less Than K.cpp b/713. Subarray Product Less Than K.cpp index 5566f6f..4d5be26 100644 --- a/713. Subarray Product Less Than K.cpp +++ b/713. Subarray Product Less Than K.cpp @@ -1,4 +1,8 @@ -//Naive +# 713. Subarray Product Less Than K + +[leetcode - 713. Subarray Product Less Than K](https://leetcode.com/problems/subarray-product-less-than-k/) + +## Naive //TLE //75 / 84 test cases passed. //time: O(N^2), space: O(1) @@ -24,11 +28,17 @@ class Solution { } }; -//Approach #1: Binary Search on Logarithms -//Runtime: 312 ms, faster than 30.64% of C++ online submissions for Subarray Product Less Than K. -//Memory Usage: 100.5 MB, less than 6.14% of C++ online submissions for Subarray Product Less Than K. -//about epsilon: https://stackoverflow.com/a/253874/10651567 -//time: O(NlogN), space: O(N) +## Approach #1: Binary Search on Logarithms + +Runtime: 312 ms, faster than 30.64% of C++ online submissions for Subarray Product Less Than K. + +Memory Usage: 100.5 MB, less than 6.14% of C++ online submissions for Subarray Product Less Than K. + +about epsilon: https://stackoverflow.com/a/253874/10651567 + +time: O(NlogN), space: O(N) + +```cpp class Solution { public: int numSubarrayProductLessThanK(vector& nums, int k) { @@ -83,11 +93,18 @@ class Solution { return ans; } }; +``` + + +## Approach #2: Sliding Window [Accepted] + +Runtime: 236 ms, faster than 98.00% of C++ online submissions for Subarray Product Less Than K. + +Memory Usage: 92.2 MB, less than 9.99% of C++ online submissions for Subarray Product Less Than K. + +time: O(N), space: O(1) -//Approach #2: Sliding Window [Accepted] -//Runtime: 236 ms, faster than 98.00% of C++ online submissions for Subarray Product Less Than K. -//Memory Usage: 92.2 MB, less than 9.99% of C++ online submissions for Subarray Product Less Than K. -//time: O(N), space: O(1) +```cpp class Solution { public: int numSubarrayProductLessThanK(vector& nums, int k) { @@ -113,3 +130,4 @@ class Solution { return ans; } }; +```