From fb91b4aa8b632a61f2c80ce4b4b3edad40af1793 Mon Sep 17 00:00:00 2001 From: YangFong <70502828+YangFong@users.noreply.github.com> Date: Sun, 6 Mar 2022 12:39:26 +0800 Subject: [PATCH] perf: optimize solutions to lc problem: No.2100 No.2100.Find Good Days to Rob the Bank --- .../2100-2199/2100.Find Good Days to Rob the Bank/README.md | 6 +++--- .../2100.Find Good Days to Rob the Bank/README_EN.md | 6 +++--- .../2100.Find Good Days to Rob the Bank/Solution.cpp | 2 +- .../2100.Find Good Days to Rob the Bank/Solution.go | 2 +- .../2100.Find Good Days to Rob the Bank/Solution.java | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/solution/2100-2199/2100.Find Good Days to Rob the Bank/README.md b/solution/2100-2199/2100.Find Good Days to Rob the Bank/README.md index 8dec9ecf87644..fcb95ba8969a2 100644 --- a/solution/2100-2199/2100.Find Good Days to Rob the Bank/README.md +++ b/solution/2100-2199/2100.Find Good Days to Rob the Bank/README.md @@ -122,7 +122,7 @@ class Solution { } } List ans = new ArrayList<>(); - for (int i = 0; i < n; ++i) { + for (int i = time; i < n - time; ++i) { if (time <= Math.min(left[i], right[i])) { ans.add(i); } @@ -149,7 +149,7 @@ public: if (security[i] <= security[i + 1]) right[i] = right[i + 1] + 1; vector ans; - for (int i = 0; i < n; ++i) + for (int i = time; i < n - time; ++i) if (time <= min(left[i], right[i])) ans.push_back(i); return ans; @@ -178,7 +178,7 @@ func goodDaysToRobBank(security []int, time int) []int { } } var ans []int - for i := 0; i < n; i++ { + for i := time; i < n - time; i++ { if time <= left[i] && time <= right[i] { ans = append(ans, i) } diff --git a/solution/2100-2199/2100.Find Good Days to Rob the Bank/README_EN.md b/solution/2100-2199/2100.Find Good Days to Rob the Bank/README_EN.md index 64002a1a09bcd..80f8b7ad83547 100644 --- a/solution/2100-2199/2100.Find Good Days to Rob the Bank/README_EN.md +++ b/solution/2100-2199/2100.Find Good Days to Rob the Bank/README_EN.md @@ -110,7 +110,7 @@ class Solution { } } List ans = new ArrayList<>(); - for (int i = 0; i < n; ++i) { + for (int i = time; i < n - time; ++i) { if (time <= Math.min(left[i], right[i])) { ans.add(i); } @@ -137,7 +137,7 @@ public: if (security[i] <= security[i + 1]) right[i] = right[i + 1] + 1; vector ans; - for (int i = 0; i < n; ++i) + for (int i = time; i < n - time; ++i) if (time <= min(left[i], right[i])) ans.push_back(i); return ans; @@ -166,7 +166,7 @@ func goodDaysToRobBank(security []int, time int) []int { } } var ans []int - for i := 0; i < n; i++ { + for i := time; i < n - time; i++ { if time <= left[i] && time <= right[i] { ans = append(ans, i) } diff --git a/solution/2100-2199/2100.Find Good Days to Rob the Bank/Solution.cpp b/solution/2100-2199/2100.Find Good Days to Rob the Bank/Solution.cpp index 35587fd3b64a9..931cda976ed09 100644 --- a/solution/2100-2199/2100.Find Good Days to Rob the Bank/Solution.cpp +++ b/solution/2100-2199/2100.Find Good Days to Rob the Bank/Solution.cpp @@ -12,7 +12,7 @@ class Solution { if (security[i] <= security[i + 1]) right[i] = right[i + 1] + 1; vector ans; - for (int i = 0; i < n; ++i) + for (int i = tiem; i < n - time; ++i) if (time <= min(left[i], right[i])) ans.push_back(i); return ans; diff --git a/solution/2100-2199/2100.Find Good Days to Rob the Bank/Solution.go b/solution/2100-2199/2100.Find Good Days to Rob the Bank/Solution.go index 6fd7baddbe495..2a01a6c72edb1 100644 --- a/solution/2100-2199/2100.Find Good Days to Rob the Bank/Solution.go +++ b/solution/2100-2199/2100.Find Good Days to Rob the Bank/Solution.go @@ -16,7 +16,7 @@ func goodDaysToRobBank(security []int, time int) []int { } } var ans []int - for i := 0; i < n; i++ { + for i := time; i < n - time; i++ { if time <= left[i] && time <= right[i] { ans = append(ans, i) } diff --git a/solution/2100-2199/2100.Find Good Days to Rob the Bank/Solution.java b/solution/2100-2199/2100.Find Good Days to Rob the Bank/Solution.java index e0ba03f8a31b6..144e91945f396 100644 --- a/solution/2100-2199/2100.Find Good Days to Rob the Bank/Solution.java +++ b/solution/2100-2199/2100.Find Good Days to Rob the Bank/Solution.java @@ -17,7 +17,7 @@ public List goodDaysToRobBank(int[] security, int time) { } } List ans = new ArrayList<>(); - for (int i = 0; i < n; ++i) { + for (int i = time; i < n - time; ++i) { if (time <= Math.min(left[i], right[i])) { ans.add(i); }