From 9818d4b2543a38015d543f4d93b9a700d8d1985b Mon Sep 17 00:00:00 2001 From: Doocs Bot Date: Wed, 13 Dec 2023 08:06:54 +0800 Subject: [PATCH 1/4] chore: auto update starcharts --- images/starcharts.svg | 46005 ++++++++++++++++++++-------------------- 1 file changed, 23055 insertions(+), 22950 deletions(-) diff --git a/images/starcharts.svg b/images/starcharts.svg index 6630bb7ae1b37..001fe576b4350 100644 --- a/images/starcharts.svg +++ b/images/starcharts.svg @@ -1,4 +1,4 @@ - + \n2018-09-252019-05-202020-01-122020-09-052021-04-302021-12-232022-08-172023-04-112023-12-04Time2019-05-212020-01-142020-09-082021-05-042021-12-282022-08-232023-04-182023-12-12Time03400 \ No newline at end of file +L 920 56 +L 920 56 +L 920 56 +L 920 56 +L 920 56 +L 920 56 +L 920 56 +L 920 56 +L 920 56 +L 920 56 +L 920 56 +L 920 56 +L 920 56 +L 920 56 +L 920 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 56 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 55 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 54 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 53 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 921 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 52 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 51 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 50 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 49 +L 922 48 +L 922 48 +L 922 48 +L 922 48 +L 922 48 +L 922 48 +L 922 48 +L 922 48 +L 922 48 +L 922 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 48 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 47 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 46 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 45 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 44 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 923 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 43 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 42 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 41 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 924 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 40 +L 925 39 +L 925 39 +L 925 39 +L 925 39 +L 925 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 926 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 39 +L 927 38 +L 927 38 +L 927 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 38 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 928 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 37 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 929 36 +L 930 36 +L 930 36 +L 930 36 +L 930 36 +L 930 36 +L 930 36 +L 930 36 +L 930 36 +L 930 36 +L 930 36 +L 930 36 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 35 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 930 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 34 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 931 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 33 +L 932 32 +L 932 32 +L 932 32 +L 932 32 +L 932 32 +L 932 32 +L 932 32 +L 932 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 32 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 933 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 31 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 934 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 30 +L 935 29 +L 935 29 +L 935 29 +L 935 29 +L 935 29 +L 935 29 +L 935 29 +L 935 29 +L 935 29 +L 935 29 +L 935 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 936 29 +L 937 29 +L 937 29 +L 937 29 +L 937 29 +L 937 29 +L 937 29 +L 937 29 +L 937 29 +L 937 29 +L 937 29 +L 937 29 +L 937 29 +L 937 29 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 937 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 28 +L 938 27 +L 938 27 +L 938 27 +L 938 27 +L 938 27 +L 938 27 +L 938 27 +L 938 27 +L 938 27 +L 938 27 +L 938 27 +L 938 27 +L 938 27 +L 938 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 939 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 27 +L 940 26 +L 940 26 +L 940 26 +L 940 26 +L 940 26 +L 940 26 +L 940 26 +L 940 26 +L 940 26 +L 940 26 +L 940 26 +L 940 26 +L 940 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 26 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 941 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 25 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 24 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 942 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 23 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 943 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 944 22 +L 945 22 +L 945 22 +L 945 22 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 945 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 946 21 +L 947 21 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 947 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 20 +L 948 19 +L 948 19 +L 948 19 +L 948 19 +L 948 19 +L 948 19 +L 948 19 +L 948 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 949 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19 +L 950 19" style="stroke-width:2;stroke:rgba(129,199,239,1.0);fill:none"/> \ No newline at end of file From 9180408ff1f8d5b608cd503160ad00c86a3fab11 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Wed, 13 Dec 2023 08:49:39 +0800 Subject: [PATCH 2/4] feat: add solutions to lc problem: No.2132 (#2092) No.2132.Stamping the Grid --- .../2132.Stamping the Grid/README.md | 302 ++++++++++-------- .../2132.Stamping the Grid/README_EN.md | 302 ++++++++++-------- .../2132.Stamping the Grid/Solution.cpp | 66 ++-- .../2132.Stamping the Grid/Solution.go | 45 +-- .../2132.Stamping the Grid/Solution.java | 65 ++-- .../2132.Stamping the Grid/Solution.js | 39 ++- .../2132.Stamping the Grid/Solution.py | 52 ++- .../2132.Stamping the Grid/Solution.ts | 33 ++ 8 files changed, 495 insertions(+), 409 deletions(-) create mode 100644 solution/2100-2199/2132.Stamping the Grid/Solution.ts diff --git a/solution/2100-2199/2132.Stamping the Grid/README.md b/solution/2100-2199/2132.Stamping the Grid/README.md index 4be4817d47cc5..93ad113e8c7d0 100644 --- a/solution/2100-2199/2132.Stamping the Grid/README.md +++ b/solution/2100-2199/2132.Stamping the Grid/README.md @@ -60,21 +60,24 @@ **方法一:二维前缀和 + 二维差分** -根据题给的约束,很容易推出,一个格子能贴邮票的条件为,在加上邮票的长和宽后,右下角不越界的情况下,当前子区域中所有格子的和为 0。 +根据题目描述,每一个空格子都必须被邮票覆盖,而且不能覆盖任何被占据的格子。因此,我们可以遍历二维矩阵,对于每个格子,如果以该格子为左上角的 $stampHeight \times stampWidth$ 的区域内的所有格子都是空格子(即没有被占据),那么我们就可以在该格子处放置一个邮票。 -那么显然我们可以维护一个二维的前缀和数组,在 `O(1)` 的时间复杂度下就可以判断每次遍历到的格子是否能贴邮票。 +为了快速判断一个区域内的所有格子是否都是空格子,我们可以使用二维前缀和。我们用 $s_{i,j}$ 表示二维矩阵中从 $(1,1)$ 到 $(i,j)$ 的子矩阵中被占据的格子的数量。即 $s_{i, j} = s_{i - 1, j} + s_{i, j - 1} - s_{i - 1, j - 1} + grid_{i-1, j-1}$。 -而因为贴邮票的操作,可以概括为将当前子区域的所有格子的值都置为 `1`,很自然的就能想到用一个二维的差分数组来维护贴邮票后的状态。 +那么以 $(i, j)$ 为左上角,且高度和宽度分别为 $stampHeight$ 和 $stampWidth$ 的子矩阵的右下角坐标为 $(x, y) = (i + stampHeight - 1, j + stampWidth - 1)$,我们可以通过 $s_{x, y} - s_{x, j - 1} - s_{i - 1, y} + s_{i - 1, j - 1}$ 来计算出该子矩阵中被占据的格子的数量。如果该子矩阵中被占据的格子的数量为 $0$,那么我们就可以在 $(i, j)$ 处放置一个邮票,放置邮票后,这 $stampHeight \times stampWidth$ 的区域内的所有格子都会变成被占据的格子,我们可以用二维差分数组 $d$ 来记录这一变化。即: -最后只要对该差分数组再求一次二维前缀和,只要当前格子的和为 `0`,就意味着存在没有覆盖完全的情况,直接返回 `false` 即可。 +$$ +\begin{aligned} +d_{i, j} &\leftarrow d_{i, j} + 1 \\ +d_{i, y + 1} &\leftarrow d_{i, y + 1} - 1 \\ +d_{x + 1, j} &\leftarrow d_{x + 1, j} - 1 \\ +d_{x + 1, y + 1} &\leftarrow d_{x + 1, y + 1} + 1 +\end{aligned} +$$ -需要注意的是二维数组的下标关系,具体参考如下。 +最后,我们对二维差分数组 $d$ 进行前缀和运算,可以得出每个格子被邮票覆盖的次数。如果某个格子没有被占据,且被邮票覆盖的次数为 $0$,那么我们就无法将邮票放置在该格子处,因此我们需要返回 $\texttt{false}$。如果所有“没被占据的格子”都成功被邮票覆盖,返回 $\texttt{true}$。 -`s[i + 1][j + 1]` 表示第 i 行第 j 列左上部分所有元素之和,其中 i, j 下标从 0 开始。 - -则 `s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + nums[i][j]`。 - -以 (x1, y1) 为左上角,(x2, y2) 为右下角的子矩阵和 `sub = s[x2 + 1][y2 + 1] - s[x2 + 1][y1] - s[x1][y2 + 1] + s[x1][y1]`。 +时间复杂度 $O(m \times n)$,空间复杂度 $O(m \times n)$。其中 $m$ 和 $n$ 分别是二维矩阵的高度和宽度。 @@ -89,26 +92,22 @@ class Solution: ) -> bool: m, n = len(grid), len(grid[0]) s = [[0] * (n + 1) for _ in range(m + 1)] - for i, row in enumerate(grid): - for j, v in enumerate(row): - s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + v - - d = [[0] * (n + 1) for _ in range(m + 1)] - for i, row in enumerate(grid): - for j, v in enumerate(row): - if v == 0: - x, y = i + stampHeight, j + stampWidth - if x <= m and y <= n and s[x][y] - s[x][j] - s[i][y] + s[i][j] == 0: - d[i][j] += 1 - d[i][y] -= 1 - d[x][j] -= 1 - d[x][y] += 1 - - cnt = [[0] * (n + 1) for _ in range(m + 1)] - for i, row in enumerate(grid): - for j, v in enumerate(row): - cnt[i + 1][j + 1] = cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + d[i][j] - if v == 0 and cnt[i + 1][j + 1] == 0: + for i, row in enumerate(grid, 1): + for j, v in enumerate(row, 1): + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + v + d = [[0] * (n + 2) for _ in range(m + 2)] + for i in range(1, m - stampHeight + 2): + for j in range(1, n - stampWidth + 2): + x, y = i + stampHeight - 1, j + stampWidth - 1 + if s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] == 0: + d[i][j] += 1 + d[i][y + 1] -= 1 + d[x + 1][j] -= 1 + d[x + 1][y + 1] += 1 + for i, row in enumerate(grid, 1): + for j, v in enumerate(row, 1): + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1] + if v == 0 and d[i][j] == 0: return False return True ``` @@ -122,30 +121,27 @@ class Solution { public boolean possibleToStamp(int[][] grid, int stampHeight, int stampWidth) { int m = grid.length, n = grid[0].length; int[][] s = new int[m + 1][n + 1]; - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + grid[i][j]; + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + grid[i - 1][j - 1]; } } - int[][] d = new int[m + 1][n + 1]; - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - if (grid[i][j] == 0) { - int x = i + stampHeight, y = j + stampWidth; - if (x <= m && y <= n && s[x][y] - s[x][j] - s[i][y] + s[i][j] == 0) { - d[i][j]++; - d[i][y]--; - d[x][j]--; - d[x][y]++; - } + int[][] d = new int[m + 2][n + 2]; + for (int i = 1; i + stampHeight - 1 <= m; ++i) { + for (int j = 1; j + stampWidth - 1 <= n; ++j) { + int x = i + stampHeight - 1, y = j + stampWidth - 1; + if (s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] == 0) { + d[i][j]++; + d[i][y + 1]--; + d[x + 1][j]--; + d[x + 1][y + 1]++; } } } - int[][] cnt = new int[m + 1][n + 1]; - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - cnt[i + 1][j + 1] = cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + d[i][j]; - if (grid[i][j] == 0 && cnt[i + 1][j + 1] == 0) { + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1]; + if (grid[i - 1][j - 1] == 0 && d[i][j] == 0) { return false; } } @@ -163,29 +159,31 @@ public: bool possibleToStamp(vector>& grid, int stampHeight, int stampWidth) { int m = grid.size(), n = grid[0].size(); vector> s(m + 1, vector(n + 1)); - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + grid[i][j]; + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + grid[i - 1][j - 1]; } } - vector> d(m + 1, vector(n + 1)); - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - if (grid[i][j]) continue; - int x = i + stampHeight, y = j + stampWidth; - if (x <= m && y <= n && s[x][y] - s[i][y] - s[x][j] + s[i][j] == 0) { + + vector> d(m + 2, vector(n + 2)); + for (int i = 1; i + stampHeight - 1 <= m; ++i) { + for (int j = 1; j + stampWidth - 1 <= n; ++j) { + int x = i + stampHeight - 1, y = j + stampWidth - 1; + if (s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] == 0) { d[i][j]++; - d[x][j]--; - d[i][y]--; - d[x][y]++; + d[i][y + 1]--; + d[x + 1][j]--; + d[x + 1][y + 1]++; } } } - vector> cnt(m + 1, vector(n + 1)); - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - cnt[i + 1][j + 1] = cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + d[i][j]; - if (grid[i][j] == 0 && cnt[i + 1][j + 1] == 0) return false; + + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1]; + if (grid[i - 1][j - 1] == 0 && d[i][j] == 0) { + return false; + } } } return true; @@ -193,6 +191,88 @@ public: }; ``` +### **Go** + +```go +func possibleToStamp(grid [][]int, stampHeight int, stampWidth int) bool { + m, n := len(grid), len(grid[0]) + s := make([][]int, m+1) + for i := range s { + s[i] = make([]int, n+1) + } + for i := 1; i <= m; i++ { + for j := 1; j <= n; j++ { + s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + grid[i-1][j-1] + } + } + + d := make([][]int, m+2) + for i := range d { + d[i] = make([]int, n+2) + } + + for i := 1; i+stampHeight-1 <= m; i++ { + for j := 1; j+stampWidth-1 <= n; j++ { + x, y := i+stampHeight-1, j+stampWidth-1 + if s[x][y]-s[x][j-1]-s[i-1][y]+s[i-1][j-1] == 0 { + d[i][j]++ + d[i][y+1]-- + d[x+1][j]-- + d[x+1][y+1]++ + } + } + } + + for i := 1; i <= m; i++ { + for j := 1; j <= n; j++ { + d[i][j] += d[i-1][j] + d[i][j-1] - d[i-1][j-1] + if grid[i-1][j-1] == 0 && d[i][j] == 0 { + return false + } + } + } + return true +} +``` + +### **TypeScript** + +```ts +function possibleToStamp(grid: number[][], stampHeight: number, stampWidth: number): boolean { + const m = grid.length; + const n = grid[0].length; + const s: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0)); + for (let i = 1; i <= m; ++i) { + for (let j = 1; j <= n; ++j) { + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + grid[i - 1][j - 1]; + } + } + + const d: number[][] = Array.from({ length: m + 2 }, () => Array(n + 2).fill(0)); + for (let i = 1; i + stampHeight - 1 <= m; ++i) { + for (let j = 1; j + stampWidth - 1 <= n; ++j) { + const [x, y] = [i + stampHeight - 1, j + stampWidth - 1]; + if (s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] === 0) { + d[i][j]++; + d[i][y + 1]--; + d[x + 1][j]--; + d[x + 1][y + 1]++; + } + } + } + + for (let i = 1; i <= m; ++i) { + for (let j = 1; j <= n; ++j) { + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1]; + if (grid[i - 1][j - 1] === 0 && d[i][j] === 0) { + return false; + } + } + } + return true; +} +``` + ### **Rust** ```rust @@ -264,49 +344,6 @@ impl Solution { } ``` -### **Go** - -```go -func possibleToStamp(grid [][]int, stampHeight int, stampWidth int) bool { - m, n := len(grid), len(grid[0]) - s := make([][]int, m+1) - d := make([][]int, m+1) - cnt := make([][]int, m+1) - for i := range s { - s[i] = make([]int, n+1) - d[i] = make([]int, n+1) - cnt[i] = make([]int, n+1) - } - for i, row := range grid { - for j, v := range row { - s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j] + v - } - } - for i, row := range grid { - for j, v := range row { - if v == 0 { - x, y := i+stampHeight, j+stampWidth - if x <= m && y <= n && s[x][y]-s[i][y]-s[x][j]+s[i][j] == 0 { - d[i][j]++ - d[i][y]-- - d[x][j]-- - d[x][y]++ - } - } - } - } - for i, row := range grid { - for j, v := range row { - cnt[i+1][j+1] = cnt[i+1][j] + cnt[i][j+1] - cnt[i][j] + d[i][j] - if v == 0 && cnt[i+1][j+1] == 0 { - return false - } - } - } - return true -} -``` - ### **JavaScript** ```js @@ -319,31 +356,30 @@ func possibleToStamp(grid [][]int, stampHeight int, stampWidth int) bool { var possibleToStamp = function (grid, stampHeight, stampWidth) { const m = grid.length; const n = grid[0].length; - let s = new Array(m + 1).fill(0).map(() => new Array(n + 1).fill(0)); - let d = new Array(m + 1).fill(0).map(() => new Array(n + 1).fill(0)); - let cnt = new Array(m + 1).fill(0).map(() => new Array(n + 1).fill(0)); - for (let i = 0; i < m; ++i) { - for (let j = 0; j < n; ++j) { - s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + grid[i][j]; + const s = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0)); + for (let i = 1; i <= m; ++i) { + for (let j = 1; j <= n; ++j) { + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + grid[i - 1][j - 1]; } } - for (let i = 0; i < m; ++i) { - for (let j = 0; j < n; ++j) { - if (grid[i][j] == 0) { - let [x, y] = [i + stampHeight, j + stampWidth]; - if (x <= m && y <= n && s[x][y] - s[i][y] - s[x][j] + s[i][j] == 0) { - d[i][j]++; - d[i][y]--; - d[x][j]--; - d[x][y]++; - } + + const d = Array.from({ length: m + 2 }, () => Array(n + 2).fill(0)); + for (let i = 1; i + stampHeight - 1 <= m; ++i) { + for (let j = 1; j + stampWidth - 1 <= n; ++j) { + const [x, y] = [i + stampHeight - 1, j + stampWidth - 1]; + if (s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] === 0) { + d[i][j]++; + d[i][y + 1]--; + d[x + 1][j]--; + d[x + 1][y + 1]++; } } } - for (let i = 0; i < m; ++i) { - for (let j = 0; j < n; ++j) { - cnt[i + 1][j + 1] = cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + d[i][j]; - if (grid[i][j] == 0 && cnt[i + 1][j + 1] == 0) { + + for (let i = 1; i <= m; ++i) { + for (let j = 1; j <= n; ++j) { + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1]; + if (grid[i - 1][j - 1] === 0 && d[i][j] === 0) { return false; } } @@ -352,14 +388,6 @@ var possibleToStamp = function (grid, stampHeight, stampWidth) { }; ``` -### **TypeScript** - - - -```ts - -``` - ### **...** ``` diff --git a/solution/2100-2199/2132.Stamping the Grid/README_EN.md b/solution/2100-2199/2132.Stamping the Grid/README_EN.md index 6994fff8c2c5b..af503fa927873 100644 --- a/solution/2100-2199/2132.Stamping the Grid/README_EN.md +++ b/solution/2100-2199/2132.Stamping the Grid/README_EN.md @@ -50,23 +50,26 @@ ## Solutions -Based on the constraints provided by the question, it's easy to infer that a cell can accommodate a stamp if, after adding the length and width of the stamp, the bottom-right corner does not exceed the boundary, and the sum of all cells in the current sub-area is zero. +**Solution 1: Two-Dimensional Prefix Sum + Two-Dimensional Difference** -Apparently, we can maintain a two-dimensional prefix sum array, and in `O(1)` time complexity, we can judge whether each cell traversed can accommodate a stamp. +According to the problem description, every empty cell must be covered by a stamp, and no occupied cell can be covered. Therefore, we can traverse the two-dimensional matrix, and for each cell, if all cells in the area of $stampHeight \times stampWidth$ with this cell as the upper left corner are empty (i.e., not occupied), then we can place a stamp at this cell. -Since the action of affixing a stamp can be generalized to setting the values of all cells in the current sub-area to `1`, it's natural to think of maintaining the state after stamp affixing using a two-dimensional difference array. +To quickly determine whether all cells in an area are empty, we can use a two-dimensional prefix sum. We use $s_{i,j}$ to represent the number of occupied cells in the sub-matrix from $(1,1)$ to $(i,j)$ in the two-dimensional matrix. That is, $s_{i, j} = s_{i - 1, j} + s_{i, j - 1} - s_{i - 1, j - 1} + grid_{i-1, j-1}$. -Finally, just calculate the two-dimensional prefix sum for this difference array again. +Then, with $(i, j)$ as the upper left corner, and the height and width are $stampHeight$ and $stampWidth$ respectively, the lower right coordinate of the sub-matrix is $(x, y) = (i + stampHeight - 1, j + stampWidth - 1)$. We can calculate the number of occupied cells in this sub-matrix through $s_{x, y} - s_{x, j - 1} - s_{i - 1, y} + s_{i - 1, j - 1}$. If the number of occupied cells in this sub-matrix is $0$, then we can place a stamp at $(i, j)$. After placing the stamp, all cells in this $stampHeight \times stampWidth$ area will become occupied cells. We can use a two-dimensional difference array $d$ to record this change. That is: -If the sum of the current cell is `0`, it means there are cases that have not been completely covered, and you can directly return `false`. +$$ +\begin{aligned} +d_{i, j} &\leftarrow d_{i, j} + 1 \\ +d_{i, y + 1} &\leftarrow d_{i, y + 1} - 1 \\ +d_{x + 1, j} &\leftarrow d_{x + 1, j} - 1 \\ +d_{x + 1, y + 1} &\leftarrow d_{x + 1, y + 1} + 1 +\end{aligned} +$$ -It's worth noting the subscript relationship of the two-dimensional array, which is as follows. +Finally, we perform a prefix sum operation on the two-dimensional difference array $d$ to find out the number of times each cell is covered by a stamp. If a cell is not occupied and the number of times it is covered by a stamp is $0$, then we cannot place a stamp at this cell, so we need to return $\texttt{false}$. If all "unoccupied cells" are successfully covered by stamps, return $\texttt{true}$. -`s[i + 1][j + 1]` represents the sum of all elements in the upper left part of the i-th row and j-th column, where the subscript i, j starts from 0. - -So `s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + nums[i][j]`. - -For a sub-matrix with (x1, y1) as the upper left corner and (x2, y2) as the bottom right corner, the sum `sub = s[x2 + 1][y2 + 1] - s[x2 + 1][y1] - s[x1][y2 + 1] + s[x1][y1]`. +The time complexity is $O(m \times n)$, and the space complexity is $O(m \times n)$. Here, $m$ and $n$ are the height and width of the two-dimensional matrix, respectively. @@ -79,26 +82,22 @@ class Solution: ) -> bool: m, n = len(grid), len(grid[0]) s = [[0] * (n + 1) for _ in range(m + 1)] - for i, row in enumerate(grid): - for j, v in enumerate(row): - s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + v - - d = [[0] * (n + 1) for _ in range(m + 1)] - for i, row in enumerate(grid): - for j, v in enumerate(row): - if v == 0: - x, y = i + stampHeight, j + stampWidth - if x <= m and y <= n and s[x][y] - s[x][j] - s[i][y] + s[i][j] == 0: - d[i][j] += 1 - d[i][y] -= 1 - d[x][j] -= 1 - d[x][y] += 1 - - cnt = [[0] * (n + 1) for _ in range(m + 1)] - for i, row in enumerate(grid): - for j, v in enumerate(row): - cnt[i + 1][j + 1] = cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + d[i][j] - if v == 0 and cnt[i + 1][j + 1] == 0: + for i, row in enumerate(grid, 1): + for j, v in enumerate(row, 1): + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + v + d = [[0] * (n + 2) for _ in range(m + 2)] + for i in range(1, m - stampHeight + 2): + for j in range(1, n - stampWidth + 2): + x, y = i + stampHeight - 1, j + stampWidth - 1 + if s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] == 0: + d[i][j] += 1 + d[i][y + 1] -= 1 + d[x + 1][j] -= 1 + d[x + 1][y + 1] += 1 + for i, row in enumerate(grid, 1): + for j, v in enumerate(row, 1): + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1] + if v == 0 and d[i][j] == 0: return False return True ``` @@ -110,30 +109,27 @@ class Solution { public boolean possibleToStamp(int[][] grid, int stampHeight, int stampWidth) { int m = grid.length, n = grid[0].length; int[][] s = new int[m + 1][n + 1]; - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + grid[i][j]; + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + grid[i - 1][j - 1]; } } - int[][] d = new int[m + 1][n + 1]; - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - if (grid[i][j] == 0) { - int x = i + stampHeight, y = j + stampWidth; - if (x <= m && y <= n && s[x][y] - s[x][j] - s[i][y] + s[i][j] == 0) { - d[i][j]++; - d[i][y]--; - d[x][j]--; - d[x][y]++; - } + int[][] d = new int[m + 2][n + 2]; + for (int i = 1; i + stampHeight - 1 <= m; ++i) { + for (int j = 1; j + stampWidth - 1 <= n; ++j) { + int x = i + stampHeight - 1, y = j + stampWidth - 1; + if (s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] == 0) { + d[i][j]++; + d[i][y + 1]--; + d[x + 1][j]--; + d[x + 1][y + 1]++; } } } - int[][] cnt = new int[m + 1][n + 1]; - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - cnt[i + 1][j + 1] = cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + d[i][j]; - if (grid[i][j] == 0 && cnt[i + 1][j + 1] == 0) { + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1]; + if (grid[i - 1][j - 1] == 0 && d[i][j] == 0) { return false; } } @@ -151,29 +147,31 @@ public: bool possibleToStamp(vector>& grid, int stampHeight, int stampWidth) { int m = grid.size(), n = grid[0].size(); vector> s(m + 1, vector(n + 1)); - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + grid[i][j]; + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + grid[i - 1][j - 1]; } } - vector> d(m + 1, vector(n + 1)); - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - if (grid[i][j]) continue; - int x = i + stampHeight, y = j + stampWidth; - if (x <= m && y <= n && s[x][y] - s[i][y] - s[x][j] + s[i][j] == 0) { + + vector> d(m + 2, vector(n + 2)); + for (int i = 1; i + stampHeight - 1 <= m; ++i) { + for (int j = 1; j + stampWidth - 1 <= n; ++j) { + int x = i + stampHeight - 1, y = j + stampWidth - 1; + if (s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] == 0) { d[i][j]++; - d[x][j]--; - d[i][y]--; - d[x][y]++; + d[i][y + 1]--; + d[x + 1][j]--; + d[x + 1][y + 1]++; } } } - vector> cnt(m + 1, vector(n + 1)); - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - cnt[i + 1][j + 1] = cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + d[i][j]; - if (grid[i][j] == 0 && cnt[i + 1][j + 1] == 0) return false; + + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1]; + if (grid[i - 1][j - 1] == 0 && d[i][j] == 0) { + return false; + } } } return true; @@ -181,6 +179,88 @@ public: }; ``` +### **Go** + +```go +func possibleToStamp(grid [][]int, stampHeight int, stampWidth int) bool { + m, n := len(grid), len(grid[0]) + s := make([][]int, m+1) + for i := range s { + s[i] = make([]int, n+1) + } + for i := 1; i <= m; i++ { + for j := 1; j <= n; j++ { + s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + grid[i-1][j-1] + } + } + + d := make([][]int, m+2) + for i := range d { + d[i] = make([]int, n+2) + } + + for i := 1; i+stampHeight-1 <= m; i++ { + for j := 1; j+stampWidth-1 <= n; j++ { + x, y := i+stampHeight-1, j+stampWidth-1 + if s[x][y]-s[x][j-1]-s[i-1][y]+s[i-1][j-1] == 0 { + d[i][j]++ + d[i][y+1]-- + d[x+1][j]-- + d[x+1][y+1]++ + } + } + } + + for i := 1; i <= m; i++ { + for j := 1; j <= n; j++ { + d[i][j] += d[i-1][j] + d[i][j-1] - d[i-1][j-1] + if grid[i-1][j-1] == 0 && d[i][j] == 0 { + return false + } + } + } + return true +} +``` + +### **TypeScript** + +```ts +function possibleToStamp(grid: number[][], stampHeight: number, stampWidth: number): boolean { + const m = grid.length; + const n = grid[0].length; + const s: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0)); + for (let i = 1; i <= m; ++i) { + for (let j = 1; j <= n; ++j) { + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + grid[i - 1][j - 1]; + } + } + + const d: number[][] = Array.from({ length: m + 2 }, () => Array(n + 2).fill(0)); + for (let i = 1; i + stampHeight - 1 <= m; ++i) { + for (let j = 1; j + stampWidth - 1 <= n; ++j) { + const [x, y] = [i + stampHeight - 1, j + stampWidth - 1]; + if (s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] === 0) { + d[i][j]++; + d[i][y + 1]--; + d[x + 1][j]--; + d[x + 1][y + 1]++; + } + } + } + + for (let i = 1; i <= m; ++i) { + for (let j = 1; j <= n; ++j) { + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1]; + if (grid[i - 1][j - 1] === 0 && d[i][j] === 0) { + return false; + } + } + } + return true; +} +``` + ### **Rust** ```rust @@ -252,49 +332,6 @@ impl Solution { } ``` -### **Go** - -```go -func possibleToStamp(grid [][]int, stampHeight int, stampWidth int) bool { - m, n := len(grid), len(grid[0]) - s := make([][]int, m+1) - d := make([][]int, m+1) - cnt := make([][]int, m+1) - for i := range s { - s[i] = make([]int, n+1) - d[i] = make([]int, n+1) - cnt[i] = make([]int, n+1) - } - for i, row := range grid { - for j, v := range row { - s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j] + v - } - } - for i, row := range grid { - for j, v := range row { - if v == 0 { - x, y := i+stampHeight, j+stampWidth - if x <= m && y <= n && s[x][y]-s[i][y]-s[x][j]+s[i][j] == 0 { - d[i][j]++ - d[i][y]-- - d[x][j]-- - d[x][y]++ - } - } - } - } - for i, row := range grid { - for j, v := range row { - cnt[i+1][j+1] = cnt[i+1][j] + cnt[i][j+1] - cnt[i][j] + d[i][j] - if v == 0 && cnt[i+1][j+1] == 0 { - return false - } - } - } - return true -} -``` - ### **JavaScript** ```js @@ -307,31 +344,30 @@ func possibleToStamp(grid [][]int, stampHeight int, stampWidth int) bool { var possibleToStamp = function (grid, stampHeight, stampWidth) { const m = grid.length; const n = grid[0].length; - let s = new Array(m + 1).fill(0).map(() => new Array(n + 1).fill(0)); - let d = new Array(m + 1).fill(0).map(() => new Array(n + 1).fill(0)); - let cnt = new Array(m + 1).fill(0).map(() => new Array(n + 1).fill(0)); - for (let i = 0; i < m; ++i) { - for (let j = 0; j < n; ++j) { - s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + grid[i][j]; + const s = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0)); + for (let i = 1; i <= m; ++i) { + for (let j = 1; j <= n; ++j) { + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + grid[i - 1][j - 1]; } } - for (let i = 0; i < m; ++i) { - for (let j = 0; j < n; ++j) { - if (grid[i][j] == 0) { - let [x, y] = [i + stampHeight, j + stampWidth]; - if (x <= m && y <= n && s[x][y] - s[i][y] - s[x][j] + s[i][j] == 0) { - d[i][j]++; - d[i][y]--; - d[x][j]--; - d[x][y]++; - } + + const d = Array.from({ length: m + 2 }, () => Array(n + 2).fill(0)); + for (let i = 1; i + stampHeight - 1 <= m; ++i) { + for (let j = 1; j + stampWidth - 1 <= n; ++j) { + const [x, y] = [i + stampHeight - 1, j + stampWidth - 1]; + if (s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] === 0) { + d[i][j]++; + d[i][y + 1]--; + d[x + 1][j]--; + d[x + 1][y + 1]++; } } } - for (let i = 0; i < m; ++i) { - for (let j = 0; j < n; ++j) { - cnt[i + 1][j + 1] = cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + d[i][j]; - if (grid[i][j] == 0 && cnt[i + 1][j + 1] == 0) { + + for (let i = 1; i <= m; ++i) { + for (let j = 1; j <= n; ++j) { + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1]; + if (grid[i - 1][j - 1] === 0 && d[i][j] === 0) { return false; } } @@ -340,12 +376,6 @@ var possibleToStamp = function (grid, stampHeight, stampWidth) { }; ``` -### **TypeScript** - -```ts - -``` - ### **...** ``` diff --git a/solution/2100-2199/2132.Stamping the Grid/Solution.cpp b/solution/2100-2199/2132.Stamping the Grid/Solution.cpp index 87b22ad8cc669..5fe5172a0871e 100644 --- a/solution/2100-2199/2132.Stamping the Grid/Solution.cpp +++ b/solution/2100-2199/2132.Stamping the Grid/Solution.cpp @@ -1,33 +1,35 @@ -class Solution { -public: - bool possibleToStamp(vector>& grid, int stampHeight, int stampWidth) { - int m = grid.size(), n = grid[0].size(); - vector> s(m + 1, vector(n + 1)); - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + grid[i][j]; - } - } - vector> d(m + 1, vector(n + 1)); - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - if (grid[i][j]) continue; - int x = i + stampHeight, y = j + stampWidth; - if (x <= m && y <= n && s[x][y] - s[i][y] - s[x][j] + s[i][j] == 0) { - d[i][j]++; - d[x][j]--; - d[i][y]--; - d[x][y]++; - } - } - } - vector> cnt(m + 1, vector(n + 1)); - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - cnt[i + 1][j + 1] = cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + d[i][j]; - if (grid[i][j] == 0 && cnt[i + 1][j + 1] == 0) return false; - } - } - return true; - } +class Solution { +public: + bool possibleToStamp(vector>& grid, int stampHeight, int stampWidth) { + int m = grid.size(), n = grid[0].size(); + vector> s(m + 1, vector(n + 1)); + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + grid[i - 1][j - 1]; + } + } + + vector> d(m + 2, vector(n + 2)); + for (int i = 1; i + stampHeight - 1 <= m; ++i) { + for (int j = 1; j + stampWidth - 1 <= n; ++j) { + int x = i + stampHeight - 1, y = j + stampWidth - 1; + if (s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] == 0) { + d[i][j]++; + d[i][y + 1]--; + d[x + 1][j]--; + d[x + 1][y + 1]++; + } + } + } + + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1]; + if (grid[i - 1][j - 1] == 0 && d[i][j] == 0) { + return false; + } + } + } + return true; + } }; \ No newline at end of file diff --git a/solution/2100-2199/2132.Stamping the Grid/Solution.go b/solution/2100-2199/2132.Stamping the Grid/Solution.go index cdf8fc435da80..0818652690c0d 100644 --- a/solution/2100-2199/2132.Stamping the Grid/Solution.go +++ b/solution/2100-2199/2132.Stamping the Grid/Solution.go @@ -1,38 +1,39 @@ func possibleToStamp(grid [][]int, stampHeight int, stampWidth int) bool { m, n := len(grid), len(grid[0]) s := make([][]int, m+1) - d := make([][]int, m+1) - cnt := make([][]int, m+1) for i := range s { s[i] = make([]int, n+1) - d[i] = make([]int, n+1) - cnt[i] = make([]int, n+1) } - for i, row := range grid { - for j, v := range row { - s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j] + v + for i := 1; i <= m; i++ { + for j := 1; j <= n; j++ { + s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + grid[i-1][j-1] } } - for i, row := range grid { - for j, v := range row { - if v == 0 { - x, y := i+stampHeight, j+stampWidth - if x <= m && y <= n && s[x][y]-s[i][y]-s[x][j]+s[i][j] == 0 { - d[i][j]++ - d[i][y]-- - d[x][j]-- - d[x][y]++ - } + + d := make([][]int, m+2) + for i := range d { + d[i] = make([]int, n+2) + } + + for i := 1; i+stampHeight-1 <= m; i++ { + for j := 1; j+stampWidth-1 <= n; j++ { + x, y := i+stampHeight-1, j+stampWidth-1 + if s[x][y]-s[x][j-1]-s[i-1][y]+s[i-1][j-1] == 0 { + d[i][j]++ + d[i][y+1]-- + d[x+1][j]-- + d[x+1][y+1]++ } } } - for i, row := range grid { - for j, v := range row { - cnt[i+1][j+1] = cnt[i+1][j] + cnt[i][j+1] - cnt[i][j] + d[i][j] - if v == 0 && cnt[i+1][j+1] == 0 { + + for i := 1; i <= m; i++ { + for j := 1; j <= n; j++ { + d[i][j] += d[i-1][j] + d[i][j-1] - d[i-1][j-1] + if grid[i-1][j-1] == 0 && d[i][j] == 0 { return false } } } return true -} \ No newline at end of file +} diff --git a/solution/2100-2199/2132.Stamping the Grid/Solution.java b/solution/2100-2199/2132.Stamping the Grid/Solution.java index 90563471af896..de13971a61a91 100644 --- a/solution/2100-2199/2132.Stamping the Grid/Solution.java +++ b/solution/2100-2199/2132.Stamping the Grid/Solution.java @@ -1,35 +1,32 @@ -class Solution { - public boolean possibleToStamp(int[][] grid, int stampHeight, int stampWidth) { - int m = grid.length, n = grid[0].length; - int[][] s = new int[m + 1][n + 1]; - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + grid[i][j]; - } - } - int[][] d = new int[m + 1][n + 1]; - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - if (grid[i][j] == 0) { - int x = i + stampHeight, y = j + stampWidth; - if (x <= m && y <= n && s[x][y] - s[x][j] - s[i][y] + s[i][j] == 0) { - d[i][j]++; - d[i][y]--; - d[x][j]--; - d[x][y]++; - } - } - } - } - int[][] cnt = new int[m + 1][n + 1]; - for (int i = 0; i < m; ++i) { - for (int j = 0; j < n; ++j) { - cnt[i + 1][j + 1] = cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + d[i][j]; - if (grid[i][j] == 0 && cnt[i + 1][j + 1] == 0) { - return false; - } - } - } - return true; - } +class Solution { + public boolean possibleToStamp(int[][] grid, int stampHeight, int stampWidth) { + int m = grid.length, n = grid[0].length; + int[][] s = new int[m + 1][n + 1]; + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + grid[i - 1][j - 1]; + } + } + int[][] d = new int[m + 2][n + 2]; + for (int i = 1; i + stampHeight - 1 <= m; ++i) { + for (int j = 1; j + stampWidth - 1 <= n; ++j) { + int x = i + stampHeight - 1, y = j + stampWidth - 1; + if (s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] == 0) { + d[i][j]++; + d[i][y + 1]--; + d[x + 1][j]--; + d[x + 1][y + 1]++; + } + } + } + for (int i = 1; i <= m; ++i) { + for (int j = 1; j <= n; ++j) { + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1]; + if (grid[i - 1][j - 1] == 0 && d[i][j] == 0) { + return false; + } + } + } + return true; + } } \ No newline at end of file diff --git a/solution/2100-2199/2132.Stamping the Grid/Solution.js b/solution/2100-2199/2132.Stamping the Grid/Solution.js index ca22ed42e2a02..7683c884de404 100644 --- a/solution/2100-2199/2132.Stamping the Grid/Solution.js +++ b/solution/2100-2199/2132.Stamping the Grid/Solution.js @@ -7,31 +7,30 @@ var possibleToStamp = function (grid, stampHeight, stampWidth) { const m = grid.length; const n = grid[0].length; - let s = new Array(m + 1).fill(0).map(() => new Array(n + 1).fill(0)); - let d = new Array(m + 1).fill(0).map(() => new Array(n + 1).fill(0)); - let cnt = new Array(m + 1).fill(0).map(() => new Array(n + 1).fill(0)); - for (let i = 0; i < m; ++i) { - for (let j = 0; j < n; ++j) { - s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + grid[i][j]; + const s = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0)); + for (let i = 1; i <= m; ++i) { + for (let j = 1; j <= n; ++j) { + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + grid[i - 1][j - 1]; } } - for (let i = 0; i < m; ++i) { - for (let j = 0; j < n; ++j) { - if (grid[i][j] == 0) { - let [x, y] = [i + stampHeight, j + stampWidth]; - if (x <= m && y <= n && s[x][y] - s[i][y] - s[x][j] + s[i][j] == 0) { - d[i][j]++; - d[i][y]--; - d[x][j]--; - d[x][y]++; - } + + const d = Array.from({ length: m + 2 }, () => Array(n + 2).fill(0)); + for (let i = 1; i + stampHeight - 1 <= m; ++i) { + for (let j = 1; j + stampWidth - 1 <= n; ++j) { + const [x, y] = [i + stampHeight - 1, j + stampWidth - 1]; + if (s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] === 0) { + d[i][j]++; + d[i][y + 1]--; + d[x + 1][j]--; + d[x + 1][y + 1]++; } } } - for (let i = 0; i < m; ++i) { - for (let j = 0; j < n; ++j) { - cnt[i + 1][j + 1] = cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + d[i][j]; - if (grid[i][j] == 0 && cnt[i + 1][j + 1] == 0) { + + for (let i = 1; i <= m; ++i) { + for (let j = 1; j <= n; ++j) { + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1]; + if (grid[i - 1][j - 1] === 0 && d[i][j] === 0) { return false; } } diff --git a/solution/2100-2199/2132.Stamping the Grid/Solution.py b/solution/2100-2199/2132.Stamping the Grid/Solution.py index 9f332811443c0..01410b59c171f 100644 --- a/solution/2100-2199/2132.Stamping the Grid/Solution.py +++ b/solution/2100-2199/2132.Stamping the Grid/Solution.py @@ -1,28 +1,24 @@ -class Solution: - def possibleToStamp( - self, grid: List[List[int]], stampHeight: int, stampWidth: int - ) -> bool: - m, n = len(grid), len(grid[0]) - s = [[0] * (n + 1) for _ in range(m + 1)] - for i, row in enumerate(grid): - for j, v in enumerate(row): - s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + v - - d = [[0] * (n + 1) for _ in range(m + 1)] - for i, row in enumerate(grid): - for j, v in enumerate(row): - if v == 0: - x, y = i + stampHeight, j + stampWidth - if x <= m and y <= n and s[x][y] - s[x][j] - s[i][y] + s[i][j] == 0: - d[i][j] += 1 - d[i][y] -= 1 - d[x][j] -= 1 - d[x][y] += 1 - - cnt = [[0] * (n + 1) for _ in range(m + 1)] - for i, row in enumerate(grid): - for j, v in enumerate(row): - cnt[i + 1][j + 1] = cnt[i + 1][j] + cnt[i][j + 1] - cnt[i][j] + d[i][j] - if v == 0 and cnt[i + 1][j + 1] == 0: - return False - return True +class Solution: + def possibleToStamp( + self, grid: List[List[int]], stampHeight: int, stampWidth: int + ) -> bool: + m, n = len(grid), len(grid[0]) + s = [[0] * (n + 1) for _ in range(m + 1)] + for i, row in enumerate(grid, 1): + for j, v in enumerate(row, 1): + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + v + d = [[0] * (n + 2) for _ in range(m + 2)] + for i in range(1, m - stampHeight + 2): + for j in range(1, n - stampWidth + 2): + x, y = i + stampHeight - 1, j + stampWidth - 1 + if s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] == 0: + d[i][j] += 1 + d[i][y + 1] -= 1 + d[x + 1][j] -= 1 + d[x + 1][y + 1] += 1 + for i, row in enumerate(grid, 1): + for j, v in enumerate(row, 1): + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1] + if v == 0 and d[i][j] == 0: + return False + return True diff --git a/solution/2100-2199/2132.Stamping the Grid/Solution.ts b/solution/2100-2199/2132.Stamping the Grid/Solution.ts new file mode 100644 index 0000000000000..37b7b2e1a849f --- /dev/null +++ b/solution/2100-2199/2132.Stamping the Grid/Solution.ts @@ -0,0 +1,33 @@ +function possibleToStamp(grid: number[][], stampHeight: number, stampWidth: number): boolean { + const m = grid.length; + const n = grid[0].length; + const s: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0)); + for (let i = 1; i <= m; ++i) { + for (let j = 1; j <= n; ++j) { + s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + grid[i - 1][j - 1]; + } + } + + const d: number[][] = Array.from({ length: m + 2 }, () => Array(n + 2).fill(0)); + for (let i = 1; i + stampHeight - 1 <= m; ++i) { + for (let j = 1; j + stampWidth - 1 <= n; ++j) { + const [x, y] = [i + stampHeight - 1, j + stampWidth - 1]; + if (s[x][y] - s[x][j - 1] - s[i - 1][y] + s[i - 1][j - 1] === 0) { + d[i][j]++; + d[i][y + 1]--; + d[x + 1][j]--; + d[x + 1][y + 1]++; + } + } + } + + for (let i = 1; i <= m; ++i) { + for (let j = 1; j <= n; ++j) { + d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1]; + if (grid[i - 1][j - 1] === 0 && d[i][j] === 0) { + return false; + } + } + } + return true; +} From b44a3980859b3e3154b352c799ffb8bc1b9de8d1 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Wed, 13 Dec 2023 11:02:45 +0800 Subject: [PATCH 3/4] feat: add solutions to lcci problems: 01.01~01.06 (#2093) --- lcci/01.01.Is Unique/README.md | 2 +- lcci/01.01.Is Unique/README_EN.md | 8 + lcci/01.02.Check Permutation/README.md | 6 +- lcci/01.02.Check Permutation/README_EN.md | 20 ++ lcci/01.03.String to URL/README.md | 4 +- lcci/01.03.String to URL/README_EN.md | 12 + lcci/01.04.Palindrome Permutation/README.md | 2 +- .../01.04.Palindrome Permutation/README_EN.md | 6 + lcci/01.05.One Away/README.md | 211 +++++++++--------- lcci/01.05.One Away/README_EN.md | 203 +++++++++-------- lcci/01.05.One Away/Solution.cpp | 55 ++--- lcci/01.05.One Away/Solution.go | 41 ++-- lcci/01.05.One Away/Solution.java | 55 ++--- lcci/01.05.One Away/Solution.py | 41 ++-- lcci/01.05.One Away/Solution.ts | 41 ++-- lcci/01.06.Compress String/README.md | 171 +++++++------- lcci/01.06.Compress String/README_EN.md | 171 +++++++------- lcci/01.06.Compress String/Solution.cpp | 17 ++ lcci/01.06.Compress String/Solution.go | 29 +-- lcci/01.06.Compress String/Solution.java | 34 ++- lcci/01.06.Compress String/Solution.js | 20 +- lcci/01.06.Compress String/Solution.py | 17 +- lcci/01.06.Compress String/Solution.rs | 29 ++- .../README.md | 8 +- .../README_EN.md | 8 +- .../Solution.ts | 2 +- 26 files changed, 663 insertions(+), 550 deletions(-) create mode 100644 lcci/01.06.Compress String/Solution.cpp diff --git a/lcci/01.01.Is Unique/README.md b/lcci/01.01.Is Unique/README.md index deb2fac1ab9e3..27083b6e429e2 100644 --- a/lcci/01.01.Is Unique/README.md +++ b/lcci/01.01.Is Unique/README.md @@ -35,7 +35,7 @@ 因此,我们可以使用一个 $32$ 位整数 `mask` 的每一位来表示字符串中的每一个字符是否出现过。 -时间复杂度 $O(n)$,空间复杂度 $O(1)$。其中 $n$ 为字符串长度。 +时间复杂度 $O(n)$,其中 $n$ 为字符串长度。空间复杂度 $O(1)$。 diff --git a/lcci/01.01.Is Unique/README_EN.md b/lcci/01.01.Is Unique/README_EN.md index ebeede799d73e..4ef688cf36a24 100644 --- a/lcci/01.01.Is Unique/README_EN.md +++ b/lcci/01.01.Is Unique/README_EN.md @@ -34,6 +34,14 @@ ## Solutions +**Solution 1: Bit Manipulation** + +Based on the examples, we can assume that the string only contains lowercase letters (which is confirmed by actual verification). + +Therefore, we can use each bit of a $32$-bit integer `mask` to represent whether each character in the string has appeared. + +The time complexity is $O(n)$, where $n$ is the length of the string. The space complexity is $O(1)$. + ### **Python3** diff --git a/lcci/01.02.Check Permutation/README.md b/lcci/01.02.Check Permutation/README.md index 1db94aece23f0..c9e985a026b62 100644 --- a/lcci/01.02.Check Permutation/README.md +++ b/lcci/01.02.Check Permutation/README.md @@ -32,7 +32,7 @@ **方法一:数组或哈希表** -先判断两个字符串的长度是否相等,若不相等则直接返回 `false`。 +我们先判断两个字符串的长度是否相等,若不相等则直接返回 `false`。 然后用一个数组或哈希表统计字符串 $s1$ 中字符出现的次数。 @@ -46,9 +46,9 @@ **方法二:排序** -按照字典序对两个字符串进行排序,然后比较两个字符串是否相等。 +我们也按照字典序对两个字符串进行排序,然后比较两个字符串是否相等。 -时间复杂度 $O(n\log n)$,空间复杂度 $O(1)$。 +时间复杂度 $O(n \times \log n)$,空间复杂度 $O(n)$。其中 $n$ 为字符串的长度。 diff --git a/lcci/01.02.Check Permutation/README_EN.md b/lcci/01.02.Check Permutation/README_EN.md index bbb2e17dfbbc4..f8bdf236e751f 100644 --- a/lcci/01.02.Check Permutation/README_EN.md +++ b/lcci/01.02.Check Permutation/README_EN.md @@ -34,6 +34,26 @@ ## Solutions +**Solution 1: Array or Hash Table** + +First, we check whether the lengths of the two strings are equal. If they are not equal, we directly return `false`. + +Then, we use an array or hash table to count the occurrence of each character in string $s1$. + +Next, we traverse the other string $s2$. For each character we encounter, we decrement its corresponding count. If the count after decrementing is less than $0$, it means that the occurrence of characters in the two strings is different, so we directly return `false`. + +Finally, after traversing string $s2$, we return `true`. + +Note: In this problem, all test case strings only contain lowercase letters, so we can directly create an array of length $26$ for counting. + +The time complexity is $O(n)$, and the space complexity is $O(C)$. Here, $n$ is the length of the string, and $C$ is the size of the character set. In this problem, $C=26$. + +**Solution 2: Sorting** + +We can also sort the two strings in lexicographical order, and then compare whether the two strings are equal. + +The time complexity is $O(n \times \log n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the string. + ### **Python3** diff --git a/lcci/01.03.String to URL/README.md b/lcci/01.03.String to URL/README.md index e407f2671a2ed..053d57851e369 100644 --- a/lcci/01.03.String to URL/README.md +++ b/lcci/01.03.String to URL/README.md @@ -33,13 +33,13 @@ 直接利用 `replace` 将所有 ` ` 替换为 `%20`: -时间复杂度 $O(n)$,空间复杂度 $O(n)$。 +时间复杂度 $O(n)$,空间复杂度 $O(n)$。其中 $n$ 为字符串长度。 **方法二:模拟** 遍历字符串每个字符 $c$,遇到空格则将 `%20` 添加到结果中,否则添加 $c$。 -时间复杂度 $O(n)$,空间复杂度 $O(n)$。 +时间复杂度 $O(n)$,空间复杂度 $O(n)$。其中 $n$ 为字符串长度。 diff --git a/lcci/01.03.String to URL/README_EN.md b/lcci/01.03.String to URL/README_EN.md index 51d49d679fffb..b5998438bc100 100644 --- a/lcci/01.03.String to URL/README_EN.md +++ b/lcci/01.03.String to URL/README_EN.md @@ -40,6 +40,18 @@ The missing numbers are [5,6,8,...], hence the third missing number is 8. ## Solutions +**Solution 1: Using `replace()` function** + +Directly use `replace` to replace all ` ` with `%20`: + +The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the string. + +**Solution 2: Simulation** + +Traverse each character $c$ in the string. When encountering a space, add `%20` to the result, otherwise add $c$. + +The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the string. + ### **Python3** diff --git a/lcci/01.04.Palindrome Permutation/README.md b/lcci/01.04.Palindrome Permutation/README.md index 75e00a592c2c4..8bcc584048b09 100644 --- a/lcci/01.04.Palindrome Permutation/README.md +++ b/lcci/01.04.Palindrome Permutation/README.md @@ -27,7 +27,7 @@ **方法一:哈希表** -我们用哈希表 `cnt` 存储每个字符出现的次数。若次数为奇数的字符超过 $1$ 个,则不是回文排列。 +我们用哈希表 $cnt$ 存储每个字符出现的次数。若次数为奇数的字符超过 $1$ 个,则不是回文排列。 时间复杂度 $O(n)$,空间复杂度 $O(n)$。其中 $n$ 为字符串长度。 diff --git a/lcci/01.04.Palindrome Permutation/README_EN.md b/lcci/01.04.Palindrome Permutation/README_EN.md index 89de7f4873d51..1065b23314301 100644 --- a/lcci/01.04.Palindrome Permutation/README_EN.md +++ b/lcci/01.04.Palindrome Permutation/README_EN.md @@ -20,6 +20,12 @@ ## Solutions +**Solution 1: Hash Table** + +We use a hash table $cnt$ to store the occurrence count of each character. If more than $1$ character has an odd count, then it is not a palindrome permutation. + +The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the string. + ### **Python3** diff --git a/lcci/01.05.One Away/README.md b/lcci/01.05.One Away/README.md index 3e4ef1d040940..e94caa36a2a21 100644 --- a/lcci/01.05.One Away/README.md +++ b/lcci/01.05.One Away/README.md @@ -30,23 +30,17 @@ second = "pal" -双指针。 +**方法一:分情况讨论 + 双指针** -先判断两字符串长度差 `diff` 是否大于 1,若是直接返回 false。 +我们将字符串 $first$ 和 $second$ 的长度记为 $m$ 和 $n$,不妨设 $m \geq n$。 -接着开始遍历两字符串。若两个指针 `i`, `j` 所指向的字符 `first[i]` 与 `second[j]` 不相同: +接下来分情况讨论: -- 若 `diff == 1`,则 `i++` -- 若 `diff == -1`,则 `j++` -- 若 `diff == 0`,则 `i++`, `j++` +- 当 $m - n \gt 1$ 时,$first$ 和 $second$ 无法通过一次编辑得到,返回 `false`; +- 当 $m = n$ 时,$first$ 和 $second$ 只有在且仅在有且仅有一个字符不同的情况下才能通过一次编辑得到; +- 当 $m - n = 1$ 时,$first$ 和 $second$ 只有在且仅在 $second$ 是 $first$ 删除一个字符后得到的情况下才能通过一次编辑得到,我们可以使用双指针来实现。 -同时编辑次数 `op` 减 1。 - -若两个指针 `i`, `j` 所指向的字符相同,则 `i++`, `j++`。 - -判断剩余编辑次数是否小于 0,若是,说明不满足一次编辑条件,直接返回 false。 - -遍历结束,直接返回 true。 +时间复杂度 $O(n)$,其中 $n$ 为字符串长度。空间复杂度 $O(1)$。 @@ -57,28 +51,21 @@ second = "pal" ```python class Solution: def oneEditAway(self, first: str, second: str) -> bool: - n1, n2 = len(first), len(second) - diff = n1 - n2 - if abs(diff) > 1: + m, n = len(first), len(second) + if m < n: + return self.oneEditAway(second, first) + if m - n > 1: return False - i, j, op = 0, 0, 1 - while i < n1 and j < n2: - not_same = first[i] != second[j] - if not_same: - if diff == 1: - i += 1 - elif diff == -1: - j += 1 - else: - i += 1 - j += 1 - op -= 1 + if m == n: + return sum(a != b for a, b in zip(first, second)) < 2 + i = j = cnt = 0 + while i < m: + if j == n or (j < n and first[i] != second[j]): + cnt += 1 else: - i += 1 j += 1 - if op < 0: - return False - return True + i += 1 + return cnt < 2 ``` ### **Java** @@ -88,29 +75,32 @@ class Solution: ```java class Solution { public boolean oneEditAway(String first, String second) { - int n1 = first.length(), n2 = second.length(); - int diff = n1 - n2; - if (Math.abs(diff) > 1) { + int m = first.length(), n = second.length(); + if (m < n) { + return oneEditAway(second, first); + } + if (m - n > 1) { return false; } - int op = 1; - for (int i = 0, j = 0; i < n1 && j < n2; ++i, ++j) { - boolean notSame = first.charAt(i) != second.charAt(j); - if (notSame) { - if (diff == 1) { - // --j, ++i, ++j => ++i - --j; - } else if (diff == -1) { - // --i, ++i, ++j => ++j - --i; + int cnt = 0; + if (m == n) { + for (int i = 0; i < n; ++i) { + if (first.charAt(i) != second.charAt(i)) { + if (++cnt > 1) { + return false; + } } - --op; } - if (op < 0) { - return false; + return true; + } + for (int i = 0, j = 0; i < m; ++i) { + if (j == n || (j < n && first.charAt(i) != second.charAt(j))) { + ++cnt; + } else { + ++j; } } - return true; + return cnt < 2; } } ``` @@ -120,65 +110,67 @@ class Solution { ```cpp class Solution { public: - bool oneEditAway(string first, string second) { - int n1 = first.size(), n2 = second.size(); - int diff = n1 - n2; - if (abs(diff) > 1) { + bool oneEditAway(std::string first, std::string second) { + int m = first.length(), n = second.length(); + if (m < n) { + return oneEditAway(second, first); + } + if (m - n > 1) { return false; } - int op = 1; - for (int i = 0, j = 0; i < n1 && j < n2; ++i, ++j) { - bool notSame = first[i] != second[j]; - if (notSame) { - if (diff == 1) { - --j; - } else if (diff == -1) { - --i; + int cnt = 0; + if (m == n) { + for (int i = 0; i < n; ++i) { + if (first[i] != second[i]) { + if (++cnt > 1) { + return false; + } } - --op; } - if (op < 0) { - return false; + return true; + } + for (int i = 0, j = 0; i < m; ++i) { + if (j == n || (j < n && first[i] != second[j])) { + ++cnt; + } else { + ++j; } } - return true; + return cnt < 2; } }; ``` ### **Go** -可以直接扩展成[编辑距离](https://leetcode.cn/problems/edit-distance/)问题的解法 - ```go func oneEditAway(first string, second string) bool { - if first == second { - return true - } m, n := len(first), len(second) - dp := make([][]int, m+1) - for i := 0; i <= m; i++ { - dp[i] = make([]int, n+1) - } - for i := 0; i <= m; i++ { - dp[i][0] = i + if m < n { + return oneEditAway(second, first) } - for j := 0; j <= n; j++ { - dp[0][j] = j + if m-n > 1 { + return false } - for i := 1; i <= m; i++ { - for j := 1; j <= n; j++ { - if first[i-1] == second[j-1] { - dp[i][j] = dp[i-1][j-1] - } else { - insert := dp[i][j-1] + 1 - delete := dp[i-1][j] + 1 - update := dp[i-1][j-1] + 1 - dp[i][j] = min(insert, delete, update) + cnt := 0 + if m == n { + for i := 0; i < n; i++ { + if first[i] != second[i] { + if cnt++; cnt > 1 { + return false + } } } + return true + } + for i, j := 0, 0; i < m; i++ { + if j == n || (j < n && first[i] != second[j]) { + cnt++ + } else { + j++ + } } - return dp[m][n] == 1 + return cnt < 2 } ``` @@ -186,26 +178,35 @@ func oneEditAway(first string, second string) bool { ```ts function oneEditAway(first: string, second: string): boolean { - const n = first.length; - const m = second.length; - - let count = 0; - let i = 0; - let j = 0; - while (i < n || j < m) { - if (first[i] !== second[j]) { - count++; - - if (i < n && first[i + 1] === second[j]) { - i++; - } else if (j < m && first[i] === second[j + 1]) { - j++; + let m: number = first.length; + let n: number = second.length; + if (m < n) { + return oneEditAway(second, first); + } + if (m - n > 1) { + return false; + } + + let cnt: number = 0; + if (m === n) { + for (let i: number = 0; i < n; ++i) { + if (first[i] !== second[i]) { + if (++cnt > 1) { + return false; + } } } - i++; - j++; + return true; + } + + for (let i: number = 0, j: number = 0; i < m; ++i) { + if (j === n || (j < n && first[i] !== second[j])) { + ++cnt; + } else { + ++j; + } } - return count <= 1; + return cnt < 2; } ``` diff --git a/lcci/01.05.One Away/README_EN.md b/lcci/01.05.One Away/README_EN.md index e56917b6a775f..b7e65457e75e9 100644 --- a/lcci/01.05.One Away/README_EN.md +++ b/lcci/01.05.One Away/README_EN.md @@ -36,6 +36,18 @@ second = "pal" ## Solutions +**Solution 1: Case Discussion + Two Pointers** + +We denote the lengths of strings $first$ and $second$ as $m$ and $n$, respectively, where $m \geq n$. + +Next, we discuss different cases: + +- When $m - n > 1$, $first$ and $second$ cannot be obtained through a single edit, so we return `false`. +- When $m = n$, $first$ and $second$ can only be obtained through a single edit if and only if exactly one character is different. +- When $m - n = 1$, $first$ and $second$ can only be obtained through a single edit if and only if $second$ is obtained by deleting one character from $first$. We can use two pointers to implement this. + +The time complexity is $O(n)$, where $n$ is the length of the string. The space complexity is $O(1)$. + ### **Python3** @@ -43,28 +55,21 @@ second = "pal" ```python class Solution: def oneEditAway(self, first: str, second: str) -> bool: - n1, n2 = len(first), len(second) - diff = n1 - n2 - if abs(diff) > 1: + m, n = len(first), len(second) + if m < n: + return self.oneEditAway(second, first) + if m - n > 1: return False - i, j, op = 0, 0, 1 - while i < n1 and j < n2: - not_same = first[i] != second[j] - if not_same: - if diff == 1: - i += 1 - elif diff == -1: - j += 1 - else: - i += 1 - j += 1 - op -= 1 + if m == n: + return sum(a != b for a, b in zip(first, second)) < 2 + i = j = cnt = 0 + while i < m: + if j == n or (j < n and first[i] != second[j]): + cnt += 1 else: - i += 1 j += 1 - if op < 0: - return False - return True + i += 1 + return cnt < 2 ``` ### **Java** @@ -72,29 +77,32 @@ class Solution: ```java class Solution { public boolean oneEditAway(String first, String second) { - int n1 = first.length(), n2 = second.length(); - int diff = n1 - n2; - if (Math.abs(diff) > 1) { + int m = first.length(), n = second.length(); + if (m < n) { + return oneEditAway(second, first); + } + if (m - n > 1) { return false; } - int op = 1; - for (int i = 0, j = 0; i < n1 && j < n2; ++i, ++j) { - boolean notSame = first.charAt(i) != second.charAt(j); - if (notSame) { - if (diff == 1) { - // --j, ++i, ++j => ++i - --j; - } else if (diff == -1) { - // --i, ++i, ++j => ++j - --i; + int cnt = 0; + if (m == n) { + for (int i = 0; i < n; ++i) { + if (first.charAt(i) != second.charAt(i)) { + if (++cnt > 1) { + return false; + } } - --op; } - if (op < 0) { - return false; + return true; + } + for (int i = 0, j = 0; i < m; ++i) { + if (j == n || (j < n && first.charAt(i) != second.charAt(j))) { + ++cnt; + } else { + ++j; } } - return true; + return cnt < 2; } } ``` @@ -104,65 +112,67 @@ class Solution { ```cpp class Solution { public: - bool oneEditAway(string first, string second) { - int n1 = first.size(), n2 = second.size(); - int diff = n1 - n2; - if (abs(diff) > 1) { + bool oneEditAway(std::string first, std::string second) { + int m = first.length(), n = second.length(); + if (m < n) { + return oneEditAway(second, first); + } + if (m - n > 1) { return false; } - int op = 1; - for (int i = 0, j = 0; i < n1 && j < n2; ++i, ++j) { - bool notSame = first[i] != second[j]; - if (notSame) { - if (diff == 1) { - --j; - } else if (diff == -1) { - --i; + int cnt = 0; + if (m == n) { + for (int i = 0; i < n; ++i) { + if (first[i] != second[i]) { + if (++cnt > 1) { + return false; + } } - --op; } - if (op < 0) { - return false; + return true; + } + for (int i = 0, j = 0; i < m; ++i) { + if (j == n || (j < n && first[i] != second[j])) { + ++cnt; + } else { + ++j; } } - return true; + return cnt < 2; } }; ``` ### **Go** -Similar to [Edit Distance](https://leetcode.cn/problems/edit-distance/) solution - ```go func oneEditAway(first string, second string) bool { - if first == second { - return true - } m, n := len(first), len(second) - dp := make([][]int, m+1) - for i := 0; i <= m; i++ { - dp[i] = make([]int, n+1) + if m < n { + return oneEditAway(second, first) } - for i := 0; i <= m; i++ { - dp[i][0] = i + if m-n > 1 { + return false } - for j := 0; j <= n; j++ { - dp[0][j] = j - } - for i := 1; i <= m; i++ { - for j := 1; j <= n; j++ { - if first[i-1] == second[j-1] { - dp[i][j] = dp[i-1][j-1] - } else { - insert := dp[i][j-1] + 1 - delete := dp[i-1][j] + 1 - update := dp[i-1][j-1] + 1 - dp[i][j] = min(insert, delete, update) + cnt := 0 + if m == n { + for i := 0; i < n; i++ { + if first[i] != second[i] { + if cnt++; cnt > 1 { + return false + } } } + return true + } + for i, j := 0, 0; i < m; i++ { + if j == n || (j < n && first[i] != second[j]) { + cnt++ + } else { + j++ + } } - return dp[m][n] == 1 + return cnt < 2 } ``` @@ -170,26 +180,35 @@ func oneEditAway(first string, second string) bool { ```ts function oneEditAway(first: string, second: string): boolean { - const n = first.length; - const m = second.length; - - let count = 0; - let i = 0; - let j = 0; - while (i < n || j < m) { - if (first[i] !== second[j]) { - count++; - - if (i < n && first[i + 1] === second[j]) { - i++; - } else if (j < m && first[i] === second[j + 1]) { - j++; + let m: number = first.length; + let n: number = second.length; + if (m < n) { + return oneEditAway(second, first); + } + if (m - n > 1) { + return false; + } + + let cnt: number = 0; + if (m === n) { + for (let i: number = 0; i < n; ++i) { + if (first[i] !== second[i]) { + if (++cnt > 1) { + return false; + } } } - i++; - j++; + return true; + } + + for (let i: number = 0, j: number = 0; i < m; ++i) { + if (j === n || (j < n && first[i] !== second[j])) { + ++cnt; + } else { + ++j; + } } - return count <= 1; + return cnt < 2; } ``` diff --git a/lcci/01.05.One Away/Solution.cpp b/lcci/01.05.One Away/Solution.cpp index 210b67fbe079e..63cd48c0494e8 100644 --- a/lcci/01.05.One Away/Solution.cpp +++ b/lcci/01.05.One Away/Solution.cpp @@ -1,26 +1,31 @@ -class Solution { -public: - bool oneEditAway(string first, string second) { - int n1 = first.size(), n2 = second.size(); - int diff = n1 - n2; - if (abs(diff) > 1) { - return false; - } - int op = 1; - for (int i = 0, j = 0; i < n1 && j < n2; ++i, ++j) { - bool notSame = first[i] != second[j]; - if (notSame) { - if (diff == 1) { - --j; - } else if (diff == -1) { - --i; - } - --op; - } - if (op < 0) { - return false; - } - } - return true; - } +class Solution { +public: + bool oneEditAway(std::string first, std::string second) { + int m = first.length(), n = second.length(); + if (m < n) { + return oneEditAway(second, first); + } + if (m - n > 1) { + return false; + } + int cnt = 0; + if (m == n) { + for (int i = 0; i < n; ++i) { + if (first[i] != second[i]) { + if (++cnt > 1) { + return false; + } + } + } + return true; + } + for (int i = 0, j = 0; i < m; ++i) { + if (j == n || (j < n && first[i] != second[j])) { + ++cnt; + } else { + ++j; + } + } + return cnt < 2; + } }; \ No newline at end of file diff --git a/lcci/01.05.One Away/Solution.go b/lcci/01.05.One Away/Solution.go index dd980a43c3bd0..45ef947758dac 100644 --- a/lcci/01.05.One Away/Solution.go +++ b/lcci/01.05.One Away/Solution.go @@ -1,29 +1,28 @@ func oneEditAway(first string, second string) bool { - if first == second { - return true - } m, n := len(first), len(second) - dp := make([][]int, m+1) - for i := 0; i <= m; i++ { - dp[i] = make([]int, n+1) - } - for i := 0; i <= m; i++ { - dp[i][0] = i + if m < n { + return oneEditAway(second, first) } - for j := 0; j <= n; j++ { - dp[0][j] = j + if m-n > 1 { + return false } - for i := 1; i <= m; i++ { - for j := 1; j <= n; j++ { - if first[i-1] == second[j-1] { - dp[i][j] = dp[i-1][j-1] - } else { - insert := dp[i][j-1] + 1 - delete := dp[i-1][j] + 1 - update := dp[i-1][j-1] + 1 - dp[i][j] = min(insert, delete, update) + cnt := 0 + if m == n { + for i := 0; i < n; i++ { + if first[i] != second[i] { + if cnt++; cnt > 1 { + return false + } } } + return true + } + for i, j := 0, 0; i < m; i++ { + if j == n || (j < n && first[i] != second[j]) { + cnt++ + } else { + j++ + } } - return dp[m][n] == 1 + return cnt < 2 } \ No newline at end of file diff --git a/lcci/01.05.One Away/Solution.java b/lcci/01.05.One Away/Solution.java index 7961fcee6fb2c..b7b519bca9098 100644 --- a/lcci/01.05.One Away/Solution.java +++ b/lcci/01.05.One Away/Solution.java @@ -1,27 +1,30 @@ -class Solution { - public boolean oneEditAway(String first, String second) { - int n1 = first.length(), n2 = second.length(); - int diff = n1 - n2; - if (Math.abs(diff) > 1) { - return false; - } - int op = 1; - for (int i = 0, j = 0; i < n1 && j < n2; ++i, ++j) { - boolean notSame = first.charAt(i) != second.charAt(j); - if (notSame) { - if (diff == 1) { - // --j, ++i, ++j => ++i - --j; - } else if (diff == -1) { - // --i, ++i, ++j => ++j - --i; - } - --op; - } - if (op < 0) { - return false; - } - } - return true; - } +class Solution { + public boolean oneEditAway(String first, String second) { + int m = first.length(), n = second.length(); + if (m < n) { + return oneEditAway(second, first); + } + if (m - n > 1) { + return false; + } + int cnt = 0; + if (m == n) { + for (int i = 0; i < n; ++i) { + if (first.charAt(i) != second.charAt(i)) { + if (++cnt > 1) { + return false; + } + } + } + return true; + } + for (int i = 0, j = 0; i < m; ++i) { + if (j == n || (j < n && first.charAt(i) != second.charAt(j))) { + ++cnt; + } else { + ++j; + } + } + return cnt < 2; + } } \ No newline at end of file diff --git a/lcci/01.05.One Away/Solution.py b/lcci/01.05.One Away/Solution.py index 0ec0a6701e645..c668638540941 100644 --- a/lcci/01.05.One Away/Solution.py +++ b/lcci/01.05.One Away/Solution.py @@ -1,24 +1,17 @@ -class Solution: - def oneEditAway(self, first: str, second: str) -> bool: - n1, n2 = len(first), len(second) - diff = n1 - n2 - if abs(diff) > 1: - return False - i, j, op = 0, 0, 1 - while i < n1 and j < n2: - not_same = first[i] != second[j] - if not_same: - if diff == 1: - i += 1 - elif diff == -1: - j += 1 - else: - i += 1 - j += 1 - op -= 1 - else: - i += 1 - j += 1 - if op < 0: - return False - return True +class Solution: + def oneEditAway(self, first: str, second: str) -> bool: + m, n = len(first), len(second) + if m < n: + return self.oneEditAway(second, first) + if m - n > 1: + return False + if m == n: + return sum(a != b for a, b in zip(first, second)) < 2 + i = j = cnt = 0 + while i < m: + if j == n or (j < n and first[i] != second[j]): + cnt += 1 + else: + j += 1 + i += 1 + return cnt < 2 diff --git a/lcci/01.05.One Away/Solution.ts b/lcci/01.05.One Away/Solution.ts index 7cae91f530815..260c4a0db3ea1 100644 --- a/lcci/01.05.One Away/Solution.ts +++ b/lcci/01.05.One Away/Solution.ts @@ -1,22 +1,31 @@ function oneEditAway(first: string, second: string): boolean { - const n = first.length; - const m = second.length; - - let count = 0; - let i = 0; - let j = 0; - while (i < n || j < m) { - if (first[i] !== second[j]) { - count++; + let m: number = first.length; + let n: number = second.length; + if (m < n) { + return oneEditAway(second, first); + } + if (m - n > 1) { + return false; + } - if (i < n && first[i + 1] === second[j]) { - i++; - } else if (j < m && first[i] === second[j + 1]) { - j++; + let cnt: number = 0; + if (m === n) { + for (let i: number = 0; i < n; ++i) { + if (first[i] !== second[i]) { + if (++cnt > 1) { + return false; + } } } - i++; - j++; + return true; + } + + for (let i: number = 0, j: number = 0; i < m; ++i) { + if (j === n || (j < n && first[i] !== second[j])) { + ++cnt; + } else { + ++j; + } } - return count <= 1; + return cnt < 2; } diff --git a/lcci/01.06.Compress String/README.md b/lcci/01.06.Compress String/README.md index 39ff8fb1bf584..a0e275aac93d8 100644 --- a/lcci/01.06.Compress String/README.md +++ b/lcci/01.06.Compress String/README.md @@ -32,7 +32,13 @@ -双指针遍历字符串求解。 +**方法一:双指针** + +我们可以利用双指针找出每个连续字符的起始位置和结束位置,计算出连续字符的长度,然后将字符和长度拼接到字符串 $t$ 中。 + +最后,我们比较 $t$ 和 $S$ 的长度,如果 $t$ 的长度小于 $S$,则返回 $t$,否则返回 $S$。 + +时间复杂度 $O(n)$,空间复杂度 $O(n)$。其中 $n$ 为字符串长度。 @@ -43,17 +49,22 @@ ```python class Solution: def compressString(self, S: str) -> str: - if len(S) < 2: - return S - p, q = 0, 1 - res = '' - while q < len(S): - if S[p] != S[q]: - res += S[p] + str(q - p) - p = q - q += 1 - res += S[p] + str(q - p) - return res if len(res) < len(S) else S + t = "".join(a + str(len(list(b))) for a, b in groupby(S)) + return min(S, t, key=len) +``` + +```python +class Solution: + def compressString(self, S: str) -> str: + t = [] + i, n = 0, len(S) + while i < n: + j = i + 1 + while j < n and S[j] == S[i]: + j += 1 + t.append(S[i] + str(j - i)) + i = j + return min(S, "".join(t), key=len) ``` ### **Java** @@ -63,47 +74,41 @@ class Solution: ```java class Solution { public String compressString(String S) { - int n; - if (S == null || (n = S.length()) < 2) { - return S; - } - int p = 0, q = 1; + int n = S.length(); StringBuilder sb = new StringBuilder(); - while (q < n) { - if (S.charAt(p) != S.charAt(q)) { - sb.append(S.charAt(p)).append(q - p); - p = q; + for (int i = 0; i < n;) { + int j = i + 1; + while (j < n && S.charAt(j) == S.charAt(i)) { + ++j; } - ++q; + sb.append(S.charAt(i)).append(j - i); + i = j; } - sb.append(S.charAt(p)).append(q - p); - String res = sb.toString(); - return res.length() < n ? res : S; + String t = sb.toString(); + return t.length() < n ? t : S; } } ``` -### **JavaScript** +### **C++** -```js -/** - * @param {string} S - * @return {string} - */ -var compressString = function (S) { - if (!S) return S; - let p = 0, - q = 1; - let res = ''; - while (q < S.length) { - if (S[p] != S[q]) { - res += S[p] + (q - p); - p = q; +```cpp +class Solution { +public: + string compressString(string S) { + int n = S.size(); + string t; + for (int i = 0; i < n;) { + int j = i + 1; + while (j < n && S[j] == S[i]) { + ++j; + } + t += S[i]; + t += to_string(j - i); + i = j; } - ++q; + return t.size() < n ? t : S; } - res += S[p] + (q - p); - return res.length < S.length ? res : S; }; ``` @@ -112,55 +117,69 @@ var compressString = function (S) { ```go func compressString(S string) string { n := len(S) - if n == 0 { - return S - } - var builder strings.Builder - pre, cnt := S[0], 1 - for i := 1; i < n; i++ { - if S[i] != pre { - builder.WriteByte(pre) - builder.WriteString(strconv.Itoa(cnt)) - cnt = 1 - } else { - cnt++ + sb := strings.Builder{} + for i := 0; i < n; { + j := i + 1 + for j < n && S[j] == S[i] { + j++ } - pre = S[i] + sb.WriteByte(S[i]) + sb.WriteString(strconv.Itoa(j - i)) + i = j } - builder.WriteByte(pre) - builder.WriteString(strconv.Itoa(cnt)) - if builder.Len() >= n { - return S + if t := sb.String(); len(t) < n { + return t } - return builder.String() + return S } ``` +### **JavaScript** + +```js +/** + * @param {string} S + * @return {string} + */ +var compressString = function (S) { + const n = S.length; + const t = []; + for (let i = 0; i < n; ) { + let j = i + 1; + while (j < n && S.charAt(j) === S.charAt(i)) { + ++j; + } + t.push(S.charAt(i), j - i); + i = j; + } + return t.length < n ? t.join('') : S; +}; +``` + ### **Rust** ```rust impl Solution { pub fn compress_string(s: String) -> String { let mut cs: Vec = s.chars().collect(); - cs.push(' '); - let mut res = vec![]; - let mut l = 0; - let mut cur = cs[0]; - for i in 1..cs.len() { - if cs[i] != cur { - let count = (i - l).to_string(); - l = i; - res.push(cur); - cur = cs[i]; - for c in count.chars() { - res.push(c); - } + let mut t = Vec::new(); + let mut i = 0; + let n = s.len(); + while i < n { + let mut j = i + 1; + while j < n && cs[j] == cs[i] { + j += 1; } + t.push(cs[i]); + t.extend((j - i).to_string().chars()); + i = j; } - if res.len() >= cs.len() - 1 { + + let t = t.into_iter().collect::(); + if s.len() <= t.len() { s } else { - res.iter().collect() + t } } } diff --git a/lcci/01.06.Compress String/README_EN.md b/lcci/01.06.Compress String/README_EN.md index 2dfcd4a3c7d8d..5c8accb3017ed 100644 --- a/lcci/01.06.Compress String/README_EN.md +++ b/lcci/01.06.Compress String/README_EN.md @@ -36,6 +36,14 @@ The compressed string is "a1b2c2d1", which is longer than the original ## Solutions +**Solution 1: Two Pointers** + +We can use two pointers to find the start and end positions of each consecutive character, calculate the length of the consecutive characters, and then append the character and length to the string $t$. + +Finally, we compare the lengths of $t$ and $S$. If the length of $t$ is less than $S$, we return $t$, otherwise we return $S$. + +The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the string. + ### **Python3** @@ -43,17 +51,22 @@ The compressed string is "a1b2c2d1", which is longer than the original ```python class Solution: def compressString(self, S: str) -> str: - if len(S) < 2: - return S - p, q = 0, 1 - res = '' - while q < len(S): - if S[p] != S[q]: - res += S[p] + str(q - p) - p = q - q += 1 - res += S[p] + str(q - p) - return res if len(res) < len(S) else S + t = "".join(a + str(len(list(b))) for a, b in groupby(S)) + return min(S, t, key=len) +``` + +```python +class Solution: + def compressString(self, S: str) -> str: + t = [] + i, n = 0, len(S) + while i < n: + j = i + 1 + while j < n and S[j] == S[i]: + j += 1 + t.append(S[i] + str(j - i)) + i = j + return min(S, "".join(t), key=len) ``` ### **Java** @@ -61,47 +74,41 @@ class Solution: ```java class Solution { public String compressString(String S) { - int n; - if (S == null || (n = S.length()) < 2) { - return S; - } - int p = 0, q = 1; + int n = S.length(); StringBuilder sb = new StringBuilder(); - while (q < n) { - if (S.charAt(p) != S.charAt(q)) { - sb.append(S.charAt(p)).append(q - p); - p = q; + for (int i = 0; i < n;) { + int j = i + 1; + while (j < n && S.charAt(j) == S.charAt(i)) { + ++j; } - ++q; + sb.append(S.charAt(i)).append(j - i); + i = j; } - sb.append(S.charAt(p)).append(q - p); - String res = sb.toString(); - return res.length() < n ? res : S; + String t = sb.toString(); + return t.length() < n ? t : S; } } ``` -### **JavaScript** +### **C++** -```js -/** - * @param {string} S - * @return {string} - */ -var compressString = function (S) { - if (!S) return S; - let p = 0, - q = 1; - let res = ''; - while (q < S.length) { - if (S[p] != S[q]) { - res += S[p] + (q - p); - p = q; +```cpp +class Solution { +public: + string compressString(string S) { + int n = S.size(); + string t; + for (int i = 0; i < n;) { + int j = i + 1; + while (j < n && S[j] == S[i]) { + ++j; + } + t += S[i]; + t += to_string(j - i); + i = j; } - ++q; + return t.size() < n ? t : S; } - res += S[p] + (q - p); - return res.length < S.length ? res : S; }; ``` @@ -110,55 +117,69 @@ var compressString = function (S) { ```go func compressString(S string) string { n := len(S) - if n == 0 { - return S - } - var builder strings.Builder - pre, cnt := S[0], 1 - for i := 1; i < n; i++ { - if S[i] != pre { - builder.WriteByte(pre) - builder.WriteString(strconv.Itoa(cnt)) - cnt = 1 - } else { - cnt++ + sb := strings.Builder{} + for i := 0; i < n; { + j := i + 1 + for j < n && S[j] == S[i] { + j++ } - pre = S[i] + sb.WriteByte(S[i]) + sb.WriteString(strconv.Itoa(j - i)) + i = j } - builder.WriteByte(pre) - builder.WriteString(strconv.Itoa(cnt)) - if builder.Len() >= n { - return S + if t := sb.String(); len(t) < n { + return t } - return builder.String() + return S } ``` +### **JavaScript** + +```js +/** + * @param {string} S + * @return {string} + */ +var compressString = function (S) { + const n = S.length; + const t = []; + for (let i = 0; i < n; ) { + let j = i + 1; + while (j < n && S.charAt(j) === S.charAt(i)) { + ++j; + } + t.push(S.charAt(i), j - i); + i = j; + } + return t.length < n ? t.join('') : S; +}; +``` + ### **Rust** ```rust impl Solution { pub fn compress_string(s: String) -> String { let mut cs: Vec = s.chars().collect(); - cs.push(' '); - let mut res = vec![]; - let mut l = 0; - let mut cur = cs[0]; - for i in 1..cs.len() { - if cs[i] != cur { - let count = (i - l).to_string(); - l = i; - res.push(cur); - cur = cs[i]; - for c in count.chars() { - res.push(c); - } + let mut t = Vec::new(); + let mut i = 0; + let n = s.len(); + while i < n { + let mut j = i + 1; + while j < n && cs[j] == cs[i] { + j += 1; } + t.push(cs[i]); + t.extend((j - i).to_string().chars()); + i = j; } - if res.len() >= cs.len() - 1 { + + let t = t.into_iter().collect::(); + if s.len() <= t.len() { s } else { - res.iter().collect() + t } } } diff --git a/lcci/01.06.Compress String/Solution.cpp b/lcci/01.06.Compress String/Solution.cpp new file mode 100644 index 0000000000000..b98486c6cdf6e --- /dev/null +++ b/lcci/01.06.Compress String/Solution.cpp @@ -0,0 +1,17 @@ +class Solution { +public: + string compressString(string S) { + int n = S.size(); + string t; + for (int i = 0; i < n;) { + int j = i + 1; + while (j < n && S[j] == S[i]) { + ++j; + } + t += S[i]; + t += to_string(j - i); + i = j; + } + return t.size() < n ? t : S; + } +}; \ No newline at end of file diff --git a/lcci/01.06.Compress String/Solution.go b/lcci/01.06.Compress String/Solution.go index 927ebe85bb750..9d54f36c4c023 100644 --- a/lcci/01.06.Compress String/Solution.go +++ b/lcci/01.06.Compress String/Solution.go @@ -1,24 +1,17 @@ func compressString(S string) string { n := len(S) - if n == 0 { - return S - } - var builder strings.Builder - pre, cnt := S[0], 1 - for i := 1; i < n; i++ { - if S[i] != pre { - builder.WriteByte(pre) - builder.WriteString(strconv.Itoa(cnt)) - cnt = 1 - } else { - cnt++ + sb := strings.Builder{} + for i := 0; i < n; { + j := i + 1 + for j < n && S[j] == S[i] { + j++ } - pre = S[i] + sb.WriteByte(S[i]) + sb.WriteString(strconv.Itoa(j - i)) + i = j } - builder.WriteByte(pre) - builder.WriteString(strconv.Itoa(cnt)) - if builder.Len() >= n { - return S + if t := sb.String(); len(t) < n { + return t } - return builder.String() + return S } \ No newline at end of file diff --git a/lcci/01.06.Compress String/Solution.java b/lcci/01.06.Compress String/Solution.java index 108334ff8f2e4..0dd24f426c6cd 100644 --- a/lcci/01.06.Compress String/Solution.java +++ b/lcci/01.06.Compress String/Solution.java @@ -1,20 +1,16 @@ -class Solution { - public String compressString(String S) { - int n; - if (S == null || (n = S.length()) < 2) { - return S; - } - int p = 0, q = 1; - StringBuilder sb = new StringBuilder(); - while (q < n) { - if (S.charAt(p) != S.charAt(q)) { - sb.append(S.charAt(p)).append(q - p); - p = q; - } - ++q; - } - sb.append(S.charAt(p)).append(q - p); - String res = sb.toString(); - return res.length() < n ? res : S; - } +class Solution { + public String compressString(String S) { + int n = S.length(); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < n;) { + int j = i + 1; + while (j < n && S.charAt(j) == S.charAt(i)) { + ++j; + } + sb.append(S.charAt(i)).append(j - i); + i = j; + } + String t = sb.toString(); + return t.length() < n ? t : S; + } } \ No newline at end of file diff --git a/lcci/01.06.Compress String/Solution.js b/lcci/01.06.Compress String/Solution.js index c21bbb9a04f58..ede54df599447 100644 --- a/lcci/01.06.Compress String/Solution.js +++ b/lcci/01.06.Compress String/Solution.js @@ -3,17 +3,15 @@ * @return {string} */ var compressString = function (S) { - if (!S) return S; - let p = 0, - q = 1; - let res = ''; - while (q < S.length) { - if (S[p] != S[q]) { - res += S[p] + (q - p); - p = q; + const n = S.length; + const t = []; + for (let i = 0; i < n; ) { + let j = i + 1; + while (j < n && S.charAt(j) === S.charAt(i)) { + ++j; } - ++q; + t.push(S.charAt(i), j - i); + i = j; } - res += S[p] + (q - p); - return res.length < S.length ? res : S; + return t.length < n ? t.join('') : S; }; diff --git a/lcci/01.06.Compress String/Solution.py b/lcci/01.06.Compress String/Solution.py index cd987c95d8f43..acfffae31ec3e 100644 --- a/lcci/01.06.Compress String/Solution.py +++ b/lcci/01.06.Compress String/Solution.py @@ -1,13 +1,4 @@ -class Solution: - def compressString(self, S: str) -> str: - if len(S) < 2: - return S - p, q = 0, 1 - res = '' - while q < len(S): - if S[p] != S[q]: - res += S[p] + str(q - p) - p = q - q += 1 - res += S[p] + str(q - p) - return res if len(res) < len(S) else S +class Solution: + def compressString(self, S: str) -> str: + t = "".join(a + str(len(list(b))) for a, b in groupby(S)) + return min(S, t, key=len) diff --git a/lcci/01.06.Compress String/Solution.rs b/lcci/01.06.Compress String/Solution.rs index 7fdf376d49b5c..ad848274dc174 100644 --- a/lcci/01.06.Compress String/Solution.rs +++ b/lcci/01.06.Compress String/Solution.rs @@ -1,25 +1,24 @@ impl Solution { pub fn compress_string(s: String) -> String { let mut cs: Vec = s.chars().collect(); - cs.push(' '); - let mut res = vec![]; - let mut l = 0; - let mut cur = cs[0]; - for i in 1..cs.len() { - if cs[i] != cur { - let count = (i - l).to_string(); - l = i; - res.push(cur); - cur = cs[i]; - for c in count.chars() { - res.push(c); - } + let mut t = Vec::new(); + let mut i = 0; + let n = s.len(); + while i < n { + let mut j = i + 1; + while j < n && cs[j] == cs[i] { + j += 1; } + t.push(cs[i]); + t.extend((j - i).to_string().chars()); + i = j; } - if res.len() >= cs.len() - 1 { + + let t = t.into_iter().collect::(); + if s.len() <= t.len() { s } else { - res.iter().collect() + t } } } diff --git a/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README.md b/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README.md index 5eda0088bf66a..f9b8a4583f711 100644 --- a/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README.md +++ b/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README.md @@ -54,9 +54,11 @@ **方法一:贪心 + 双指针** -我们用两个指针 $i$ 和 $j$ 分别指向字符串的首尾,初始时 $i = 0$, $j = n - 1$。每一次,我们将 $s[i]$ 和 $s[j]$ 都修改为其中较小的那个字符,使得它们相等。修改之后,原字符串 $s$ 变成了一个回文串。 +我们用两个指针 $i$ 和 $j$ 分别指向字符串的首尾,初始时 $i = 0$, $j = n - 1$。 -时间复杂度 $O(n)$,其中 $n$ 是字符串的长度。我们只需要遍历一遍字符串即可。忽略答案的空间消耗,空间复杂度 $O(1)$。 +接下来,我们每一次都贪心地将 $s[i]$ 和 $s[j]$ 修改为它们中的较小值,使得它们相等。然后将 $i$ 向后移动一位,将 $j$ 向前移动一位,继续进行这一过程,直到 $i \ge j$ 为止。此时,我们就得到了最小的回文串。 + +时间复杂度 $O(n)$,空间复杂度 $O(n)$。其中 $n$ 是字符串的长度。 @@ -124,7 +126,7 @@ func makeSmallestPalindrome(s string) string { function makeSmallestPalindrome(s: string): string { const cs = s.split(''); for (let i = 0, j = s.length - 1; i < j; ++i, --j) { - cs[i] = cs[j] = String.fromCharCode(Math.min(cs[i].charCodeAt(0), cs[j].charCodeAt(0))); + cs[i] = cs[j] = s[i] < s[j] ? s[i] : s[j]; } return cs.join(''); } diff --git a/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README_EN.md b/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README_EN.md index 85ec129d7aa88..7a74d964ba58a 100644 --- a/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README_EN.md +++ b/solution/2600-2699/2697.Lexicographically Smallest Palindrome/README_EN.md @@ -49,9 +49,11 @@ **Solution 1: Greedy + Two Pointers** -We use two pointers $i$ and $j$ to point to the beginning and end of the string, initially $i=0,j=n-1$, where $n$ is the length of the string. Each time we compare $s[i]$ and $s[j]$, if they are not the same, we modify the larger character to the smaller one to make them the same. After the modification, the original string $s$ becomes a palindrome. +We use two pointers $i$ and $j$ to point to the beginning and end of the string, initially $i = 0$, $j = n - 1$. -The time complexity is $O(n)$, where $n$ is the length of the string. We only need to traverse the string once. Ignoring the space consumption of the answer, the space complexity is $O(1)$. +Next, each time we greedily modify $s[i]$ and $s[j]$ to their smaller value to make them equal. Then we move $i$ one step forward and $j$ one step backward, and continue this process until $i \ge j$. At this point, we have obtained the smallest palindrome string. + +The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is the length of the string. @@ -115,7 +117,7 @@ func makeSmallestPalindrome(s string) string { function makeSmallestPalindrome(s: string): string { const cs = s.split(''); for (let i = 0, j = s.length - 1; i < j; ++i, --j) { - cs[i] = cs[j] = String.fromCharCode(Math.min(cs[i].charCodeAt(0), cs[j].charCodeAt(0))); + cs[i] = cs[j] = s[i] < s[j] ? s[i] : s[j]; } return cs.join(''); } diff --git a/solution/2600-2699/2697.Lexicographically Smallest Palindrome/Solution.ts b/solution/2600-2699/2697.Lexicographically Smallest Palindrome/Solution.ts index 4d4f567aef53a..345bd762e63a0 100644 --- a/solution/2600-2699/2697.Lexicographically Smallest Palindrome/Solution.ts +++ b/solution/2600-2699/2697.Lexicographically Smallest Palindrome/Solution.ts @@ -1,7 +1,7 @@ function makeSmallestPalindrome(s: string): string { const cs = s.split(''); for (let i = 0, j = s.length - 1; i < j; ++i, --j) { - cs[i] = cs[j] = String.fromCharCode(Math.min(cs[i].charCodeAt(0), cs[j].charCodeAt(0))); + cs[i] = cs[j] = s[i] < s[j] ? s[i] : s[j]; } return cs.join(''); } From 25c77f3fcd86251589291e82fdd1cb60bff30361 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Wed, 13 Dec 2023 11:23:03 +0800 Subject: [PATCH 4/4] feat: add solutions to lcci problems: No.01.07~01.09 (#2094) --- lcci/01.07.Rotate Matrix/README.md | 168 ++++++++++++++++++------ lcci/01.07.Rotate Matrix/README_EN.md | 168 ++++++++++++++++++------ lcci/01.07.Rotate Matrix/Solution.cpp | 16 +++ lcci/01.07.Rotate Matrix/Solution.cs | 19 +++ lcci/01.07.Rotate Matrix/Solution.go | 16 +-- lcci/01.07.Rotate Matrix/Solution.java | 31 +++-- lcci/01.07.Rotate Matrix/Solution.js | 12 +- lcci/01.07.Rotate Matrix/Solution.py | 22 ++-- lcci/01.07.Rotate Matrix/Solution.rs | 19 +++ lcci/01.07.Rotate Matrix/Solution.ts | 13 ++ lcci/01.08.Zero Matrix/README.md | 4 +- lcci/01.08.Zero Matrix/README_EN.md | 16 +++ lcci/01.09.String Rotation/README_EN.md | 21 +++ 13 files changed, 404 insertions(+), 121 deletions(-) create mode 100644 lcci/01.07.Rotate Matrix/Solution.cpp create mode 100644 lcci/01.07.Rotate Matrix/Solution.cs create mode 100644 lcci/01.07.Rotate Matrix/Solution.rs create mode 100644 lcci/01.07.Rotate Matrix/Solution.ts diff --git a/lcci/01.07.Rotate Matrix/README.md b/lcci/01.07.Rotate Matrix/README.md index 75549ff610874..40c6c818acad3 100644 --- a/lcci/01.07.Rotate Matrix/README.md +++ b/lcci/01.07.Rotate Matrix/README.md @@ -51,7 +51,13 @@ -原地旋转,i 的范围是 `[0, n/2)`,j 的范围是 `[i, n-1-i)`。 +**方法一:原地翻转** + +根据题目要求,我们实际上需要将 $matrix[i][j]$ 旋转至 $matrix[j][n - i - 1]$。 + +我们可以先对矩阵进行上下翻转,即 $matrix[i][j]$ 和 $matrix[n - i - 1][j]$ 进行交换,然后再对矩阵进行主对角线翻转,即 $matrix[i][j]$ 和 $matrix[j][i]$ 进行交换。这样就能将 $matrix[i][j]$ 旋转至 $matrix[j][n - i - 1]$ 了。 + +时间复杂度 $O(n^2)$,其中 $n$ 是矩阵的边长。空间复杂度 $O(1)$。 @@ -62,17 +68,13 @@ ```python class Solution: def rotate(self, matrix: List[List[int]]) -> None: - """ - Do not return anything, modify matrix in-place instead. - """ n = len(matrix) - for i in range(n // 2): - for j in range(i, n - 1 - i): - t = matrix[i][j] - matrix[i][j] = matrix[n - j - 1][i] - matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1] - matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1] - matrix[j][n - i - 1] = t + for i in range(n >> 1): + for j in range(n): + matrix[i][j], matrix[n - i - 1][j] = matrix[n - i - 1][j], matrix[i][j] + for i in range(n): + for j in range(i): + matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] ``` ### **Java** @@ -83,19 +85,63 @@ class Solution: class Solution { public void rotate(int[][] matrix) { int n = matrix.length; - for (int i = 0; i < n / 2; ++i) { - for (int j = i; j < n - 1 - i; ++j) { + for (int i = 0; i < n >> 1; ++i) { + for (int j = 0; j < n; ++j) { + int t = matrix[i][j]; + matrix[i][j] = matrix[n - i - 1][j]; + matrix[n - i - 1][j] = t; + } + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < i; ++j) { int t = matrix[i][j]; - matrix[i][j] = matrix[n - j - 1][i]; - matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1]; - matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1]; - matrix[j][n - i - 1] = t; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = t; } } } } ``` +### **C++** + +```cpp +class Solution { +public: + void rotate(vector>& matrix) { + int n = matrix.size(); + for (int i = 0; i < n >> 1; ++i) { + for (int j = 0; j < n; ++j) { + swap(matrix[i][j], matrix[n - i - 1][j]); + } + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < i; ++j) { + swap(matrix[i][j], matrix[j][i]); + } + } + } +}; +``` + +### **Go** + +```go +func rotate(matrix [][]int) { + n := len(matrix) + for i := 0; i < n>>1; i++ { + for j := 0; j < n; j++ { + matrix[i][j], matrix[n-i-1][j] = matrix[n-i-1][j], matrix[i][j] + } + } + for i := 0; i < n; i++ { + for j := 0; j < i; j++ { + matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] + } + } +} +``` + ### **JavaScript** ```js @@ -104,34 +150,78 @@ class Solution { * @return {void} Do not return anything, modify matrix in-place instead. */ var rotate = function (matrix) { - const n = matrix.length; - for (let i = 0; i < n / 2; i++) { - for (let j = i; j < n - i - 1; j++) { - let t = matrix[i][j]; - matrix[i][j] = matrix[n - j - 1][i]; - matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1]; - matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1]; - matrix[j][n - i - 1] = t; + matrix.reverse(); + for (let i = 0; i < matrix.length; ++i) { + for (let j = 0; j < i; ++j) { + [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]]; } } }; ``` -### **Go** +### **TypeScript** -```go -func rotate(matrix [][]int) { - n := len(matrix) - r, c := n/2, (n+1)/2 - for i := 0; i < r; i++ { - for j := 0; j < c; j++ { - temp := matrix[i][j] - matrix[i][j] = matrix[n-j-1][i] - matrix[n-j-1][i] = matrix[n-i-1][n-j-1] - matrix[n-i-1][n-j-1] = matrix[j][n-i-1] - matrix[j][n-i-1] = temp - } - } +```ts +/** + Do not return anything, modify matrix in-place instead. + */ +function rotate(matrix: number[][]): void { + matrix.reverse(); + for (let i = 0; i < matrix.length; ++i) { + for (let j = 0; j < i; ++j) { + const t = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = t; + } + } +} +``` + +### **C#** + +```cs +public class Solution { + public void Rotate(int[][] matrix) { + int n = matrix.Length; + for (int i = 0; i < n >> 1; ++i) { + for (int j = 0; j < n; ++j) { + int t = matrix[i][j]; + matrix[i][j] = matrix[n - i - 1][j]; + matrix[n - i - 1][j] = t; + } + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < i; ++j) { + int t = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = t; + } + } + } +} +``` + +### **Rust** + +```rust +impl Solution { + pub fn rotate(matrix: &mut Vec>) { + let n = matrix.len(); + for i in 0..n / 2 { + for j in 0..n { + let t = matrix[i][j]; + matrix[i][j] = matrix[n - i - 1][j]; + matrix[n - i - 1][j] = t; + } + } + for i in 0..n { + for j in 0..i { + let t = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = t; + } + } + } } ``` diff --git a/lcci/01.07.Rotate Matrix/README_EN.md b/lcci/01.07.Rotate Matrix/README_EN.md index 31ade449f0160..76919c602c597 100644 --- a/lcci/01.07.Rotate Matrix/README_EN.md +++ b/lcci/01.07.Rotate Matrix/README_EN.md @@ -78,6 +78,14 @@ Rotate the matrix in place. It becomes: ## Solutions +**Solution 1: In-place Rotation** + +According to the problem requirements, we actually need to rotate $matrix[i][j]$ to $matrix[j][n - i - 1]$. + +We can first flip the matrix upside down, that is, swap $matrix[i][j]$ and $matrix[n - i - 1][j]$, and then flip the matrix along the main diagonal, that is, swap $matrix[i][j]$ and $matrix[j][i]$. This way, we can rotate $matrix[i][j]$ to $matrix[j][n - i - 1]$. + +The time complexity is $O(n^2)$, where $n$ is the side length of the matrix. The space complexity is $O(1)$. + ### **Python3** @@ -85,17 +93,13 @@ Rotate the matrix in place. It becomes: ```python class Solution: def rotate(self, matrix: List[List[int]]) -> None: - """ - Do not return anything, modify matrix in-place instead. - """ n = len(matrix) - for i in range(n // 2): - for j in range(i, n - 1 - i): - t = matrix[i][j] - matrix[i][j] = matrix[n - j - 1][i] - matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1] - matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1] - matrix[j][n - i - 1] = t + for i in range(n >> 1): + for j in range(n): + matrix[i][j], matrix[n - i - 1][j] = matrix[n - i - 1][j], matrix[i][j] + for i in range(n): + for j in range(i): + matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] ``` ### **Java** @@ -104,19 +108,63 @@ class Solution: class Solution { public void rotate(int[][] matrix) { int n = matrix.length; - for (int i = 0; i < n / 2; ++i) { - for (int j = i; j < n - 1 - i; ++j) { + for (int i = 0; i < n >> 1; ++i) { + for (int j = 0; j < n; ++j) { int t = matrix[i][j]; - matrix[i][j] = matrix[n - j - 1][i]; - matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1]; - matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1]; - matrix[j][n - i - 1] = t; + matrix[i][j] = matrix[n - i - 1][j]; + matrix[n - i - 1][j] = t; + } + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < i; ++j) { + int t = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = t; } } } } ``` +### **C++** + +```cpp +class Solution { +public: + void rotate(vector>& matrix) { + int n = matrix.size(); + for (int i = 0; i < n >> 1; ++i) { + for (int j = 0; j < n; ++j) { + swap(matrix[i][j], matrix[n - i - 1][j]); + } + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < i; ++j) { + swap(matrix[i][j], matrix[j][i]); + } + } + } +}; +``` + +### **Go** + +```go +func rotate(matrix [][]int) { + n := len(matrix) + for i := 0; i < n>>1; i++ { + for j := 0; j < n; j++ { + matrix[i][j], matrix[n-i-1][j] = matrix[n-i-1][j], matrix[i][j] + } + } + for i := 0; i < n; i++ { + for j := 0; j < i; j++ { + matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] + } + } +} +``` + ### **JavaScript** ```js @@ -125,34 +173,78 @@ class Solution { * @return {void} Do not return anything, modify matrix in-place instead. */ var rotate = function (matrix) { - const n = matrix.length; - for (let i = 0; i < n / 2; i++) { - for (let j = i; j < n - i - 1; j++) { - let t = matrix[i][j]; - matrix[i][j] = matrix[n - j - 1][i]; - matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1]; - matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1]; - matrix[j][n - i - 1] = t; + matrix.reverse(); + for (let i = 0; i < matrix.length; ++i) { + for (let j = 0; j < i; ++j) { + [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]]; } } }; ``` -### **Go** +### **TypeScript** -```go -func rotate(matrix [][]int) { - n := len(matrix) - r, c := n/2, (n+1)/2 - for i := 0; i < r; i++ { - for j := 0; j < c; j++ { - temp := matrix[i][j] - matrix[i][j] = matrix[n-j-1][i] - matrix[n-j-1][i] = matrix[n-i-1][n-j-1] - matrix[n-i-1][n-j-1] = matrix[j][n-i-1] - matrix[j][n-i-1] = temp - } - } +```ts +/** + Do not return anything, modify matrix in-place instead. + */ +function rotate(matrix: number[][]): void { + matrix.reverse(); + for (let i = 0; i < matrix.length; ++i) { + for (let j = 0; j < i; ++j) { + const t = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = t; + } + } +} +``` + +### **C#** + +```cs +public class Solution { + public void Rotate(int[][] matrix) { + int n = matrix.Length; + for (int i = 0; i < n >> 1; ++i) { + for (int j = 0; j < n; ++j) { + int t = matrix[i][j]; + matrix[i][j] = matrix[n - i - 1][j]; + matrix[n - i - 1][j] = t; + } + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < i; ++j) { + int t = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = t; + } + } + } +} +``` + +### **Rust** + +```rust +impl Solution { + pub fn rotate(matrix: &mut Vec>) { + let n = matrix.len(); + for i in 0..n / 2 { + for j in 0..n { + let t = matrix[i][j]; + matrix[i][j] = matrix[n - i - 1][j]; + matrix[n - i - 1][j] = t; + } + } + for i in 0..n { + for j in 0..i { + let t = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = t; + } + } + } } ``` diff --git a/lcci/01.07.Rotate Matrix/Solution.cpp b/lcci/01.07.Rotate Matrix/Solution.cpp new file mode 100644 index 0000000000000..a769be400f3fc --- /dev/null +++ b/lcci/01.07.Rotate Matrix/Solution.cpp @@ -0,0 +1,16 @@ +class Solution { +public: + void rotate(vector>& matrix) { + int n = matrix.size(); + for (int i = 0; i < n >> 1; ++i) { + for (int j = 0; j < n; ++j) { + swap(matrix[i][j], matrix[n - i - 1][j]); + } + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < i; ++j) { + swap(matrix[i][j], matrix[j][i]); + } + } + } +}; \ No newline at end of file diff --git a/lcci/01.07.Rotate Matrix/Solution.cs b/lcci/01.07.Rotate Matrix/Solution.cs new file mode 100644 index 0000000000000..ede95719d847d --- /dev/null +++ b/lcci/01.07.Rotate Matrix/Solution.cs @@ -0,0 +1,19 @@ +public class Solution { + public void Rotate(int[][] matrix) { + int n = matrix.Length; + for (int i = 0; i < n >> 1; ++i) { + for (int j = 0; j < n; ++j) { + int t = matrix[i][j]; + matrix[i][j] = matrix[n - i - 1][j]; + matrix[n - i - 1][j] = t; + } + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < i; ++j) { + int t = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = t; + } + } + } +} \ No newline at end of file diff --git a/lcci/01.07.Rotate Matrix/Solution.go b/lcci/01.07.Rotate Matrix/Solution.go index 9651414dc653f..3210ff1d87dc2 100644 --- a/lcci/01.07.Rotate Matrix/Solution.go +++ b/lcci/01.07.Rotate Matrix/Solution.go @@ -1,13 +1,13 @@ func rotate(matrix [][]int) { n := len(matrix) - r, c := n/2, (n+1)/2 - for i := 0; i < r; i++ { - for j := 0; j < c; j++ { - temp := matrix[i][j] - matrix[i][j] = matrix[n-j-1][i] - matrix[n-j-1][i] = matrix[n-i-1][n-j-1] - matrix[n-i-1][n-j-1] = matrix[j][n-i-1] - matrix[j][n-i-1] = temp + for i := 0; i < n>>1; i++ { + for j := 0; j < n; j++ { + matrix[i][j], matrix[n-i-1][j] = matrix[n-i-1][j], matrix[i][j] + } + } + for i := 0; i < n; i++ { + for j := 0; j < i; j++ { + matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] } } } \ No newline at end of file diff --git a/lcci/01.07.Rotate Matrix/Solution.java b/lcci/01.07.Rotate Matrix/Solution.java index 6b9b38b53d8d5..54162c23dc0aa 100644 --- a/lcci/01.07.Rotate Matrix/Solution.java +++ b/lcci/01.07.Rotate Matrix/Solution.java @@ -1,14 +1,19 @@ -class Solution { - public void rotate(int[][] matrix) { - int n = matrix.length; - for (int i = 0; i < n / 2; ++i) { - for (int j = i; j < n - 1 - i; ++j) { - int t = matrix[i][j]; - matrix[i][j] = matrix[n - j - 1][i]; - matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1]; - matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1]; - matrix[j][n - i - 1] = t; - } - } - } +class Solution { + public void rotate(int[][] matrix) { + int n = matrix.length; + for (int i = 0; i < n >> 1; ++i) { + for (int j = 0; j < n; ++j) { + int t = matrix[i][j]; + matrix[i][j] = matrix[n - i - 1][j]; + matrix[n - i - 1][j] = t; + } + } + for (int i = 0; i < n; ++i) { + for (int j = 0; j < i; ++j) { + int t = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = t; + } + } + } } \ No newline at end of file diff --git a/lcci/01.07.Rotate Matrix/Solution.js b/lcci/01.07.Rotate Matrix/Solution.js index 520bbd794d850..e286e7fbcd857 100644 --- a/lcci/01.07.Rotate Matrix/Solution.js +++ b/lcci/01.07.Rotate Matrix/Solution.js @@ -3,14 +3,10 @@ * @return {void} Do not return anything, modify matrix in-place instead. */ var rotate = function (matrix) { - const n = matrix.length; - for (let i = 0; i < n / 2; i++) { - for (let j = i; j < n - i - 1; j++) { - let t = matrix[i][j]; - matrix[i][j] = matrix[n - j - 1][i]; - matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1]; - matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1]; - matrix[j][n - i - 1] = t; + matrix.reverse(); + for (let i = 0; i < matrix.length; ++i) { + for (let j = 0; j < i; ++j) { + [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]]; } } }; diff --git a/lcci/01.07.Rotate Matrix/Solution.py b/lcci/01.07.Rotate Matrix/Solution.py index 950a8e3a75f87..d8eb627b11a86 100644 --- a/lcci/01.07.Rotate Matrix/Solution.py +++ b/lcci/01.07.Rotate Matrix/Solution.py @@ -1,13 +1,9 @@ -class Solution: - def rotate(self, matrix: List[List[int]]) -> None: - """ - Do not return anything, modify matrix in-place instead. - """ - n = len(matrix) - for i in range(n // 2): - for j in range(i, n - 1 - i): - t = matrix[i][j] - matrix[i][j] = matrix[n - j - 1][i] - matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1] - matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1] - matrix[j][n - i - 1] = t +class Solution: + def rotate(self, matrix: List[List[int]]) -> None: + n = len(matrix) + for i in range(n >> 1): + for j in range(n): + matrix[i][j], matrix[n - i - 1][j] = matrix[n - i - 1][j], matrix[i][j] + for i in range(n): + for j in range(i): + matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] diff --git a/lcci/01.07.Rotate Matrix/Solution.rs b/lcci/01.07.Rotate Matrix/Solution.rs new file mode 100644 index 0000000000000..06552d6ffb320 --- /dev/null +++ b/lcci/01.07.Rotate Matrix/Solution.rs @@ -0,0 +1,19 @@ +impl Solution { + pub fn rotate(matrix: &mut Vec>) { + let n = matrix.len(); + for i in 0..n / 2 { + for j in 0..n { + let t = matrix[i][j]; + matrix[i][j] = matrix[n - i - 1][j]; + matrix[n - i - 1][j] = t; + } + } + for i in 0..n { + for j in 0..i { + let t = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = t; + } + } + } +} diff --git a/lcci/01.07.Rotate Matrix/Solution.ts b/lcci/01.07.Rotate Matrix/Solution.ts new file mode 100644 index 0000000000000..dc5db727b61f8 --- /dev/null +++ b/lcci/01.07.Rotate Matrix/Solution.ts @@ -0,0 +1,13 @@ +/** + Do not return anything, modify matrix in-place instead. + */ +function rotate(matrix: number[][]): void { + matrix.reverse(); + for (let i = 0; i < matrix.length; ++i) { + for (let j = 0; j < i; ++j) { + const t = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = t; + } + } +} diff --git a/lcci/01.08.Zero Matrix/README.md b/lcci/01.08.Zero Matrix/README.md index 45873f096f12b..216985d14f3a0 100644 --- a/lcci/01.08.Zero Matrix/README.md +++ b/lcci/01.08.Zero Matrix/README.md @@ -51,7 +51,7 @@ 然后再遍历一遍矩阵,将 `rows` 和 `cols` 中标记的行和列对应的元素清零。 -时间复杂度 $O(m\times n)$,空间复杂度 $O(m+n)$。其中 $m$ 和 $n$ 分别为矩阵的行数和列数。 +时间复杂度 $O(m \times n)$,空间复杂度 $O(m + n)$。其中 $m$ 和 $n$ 分别为矩阵的行数和列数。 **方法二:原地标记** @@ -59,7 +59,7 @@ 由于第一行、第一列用来做标记,它们的值可能会因为标记而发生改变,因此,我们需要额外的变量 $i0$, $j0$ 来标记第一行、第一列是否需要被清零。 -时间复杂度 $O(m\times n)$,空间复杂度 $O(1)$。其中 $m$ 和 $n$ 分别为矩阵的行数和列数。 +时间复杂度 $O(m \times n)$,其中 $m$ 和 $n$ 分别为矩阵的行数和列数。空间复杂度 $O(1)$。 diff --git a/lcci/01.08.Zero Matrix/README_EN.md b/lcci/01.08.Zero Matrix/README_EN.md index 797cf275208c8..5a7ead1edc030 100644 --- a/lcci/01.08.Zero Matrix/README_EN.md +++ b/lcci/01.08.Zero Matrix/README_EN.md @@ -70,6 +70,22 @@ ## Solutions +**Solution 1: Array Marking** + +We use arrays `rows` and `cols` to mark the rows and columns to be zeroed. + +Then we traverse the matrix again, zeroing the elements corresponding to the rows and columns marked in `rows` and `cols`. + +The time complexity is $O(m \times n)$, and the space complexity is $O(m + n)$. Here, $m$ and $n$ are the number of rows and columns of the matrix, respectively. + +**Solution 2: In-place Marking** + +In Solution 1, we used additional arrays to mark the rows and columns to be zeroed. In fact, we can directly use the first row and first column of the matrix for marking, without needing to allocate additional array space. + +Since the first row and first column are used for marking, their values may change due to the marking. Therefore, we need additional variables $i0$ and $j0$ to mark whether the first row and first column need to be zeroed. + +The time complexity is $O(m \times n)$, where $m$ and $n$ are the number of rows and columns of the matrix, respectively. The space complexity is $O(1)$. + ### **Python3** diff --git a/lcci/01.09.String Rotation/README_EN.md b/lcci/01.09.String Rotation/README_EN.md index e35c37081b08e..eb31c0a5ebe87 100644 --- a/lcci/01.09.String Rotation/README_EN.md +++ b/lcci/01.09.String Rotation/README_EN.md @@ -36,6 +36,27 @@ ## Solutions +**Solution 1: String Matching** + +First, if the lengths of strings $s1$ and $s2$ are not equal, they are definitely not rotation strings of each other. + +Second, if the lengths of strings $s1$ and $s2$ are equal, then by concatenating two $s1$ together, the resulting string $s1 + s1$ will definitely include all rotation cases of $s1$. At this point, we just need to check whether $s2$ is a substring of $s1 + s1$. + +```bash +# True +s1 = "aba" +s2 = "baa" +s1 + s1 = "abaaba" + ^^^ + +# False +s1 = "aba" +s2 = "bab" +s1 + s1 = "abaaba" +``` + +The time complexity is $O(n)$, and the space complexity is $O(n)$. Here, $n$ is the length of string $s1$. + ### **Python3**