From da0d5dcf50f8fa8def91abaafce1fd5624ec1a61 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 8 Jan 2024 19:15:36 +0000 Subject: i- Added solutions by Mark Anderson. - Added solutions by PokGoPun. - Added solutions by Simon Proctor. - Added solutions by Luca Ferrari. - Added solutions by Thomas Kohler. - Added solutions by Peter Campbell Smith. - Added solutions by Niels van Dijke. - Added solutions by W. Luis Mochan. - Added solutions by David Ferrone. - Added solutions by Dave Jacoby. - Added solutions by Peter Meszaros. - Added solutions by Laurent Rosenfeld. --- challenge-250/eric-cheung/python/ch-1.py | 25 ++++++++++++++++--------- challenge-250/eric-cheung/python/ch-2.py | 16 ++++++++++------ 2 files changed, 26 insertions(+), 15 deletions(-) (limited to 'challenge-250/eric-cheung/python') diff --git a/challenge-250/eric-cheung/python/ch-1.py b/challenge-250/eric-cheung/python/ch-1.py index 3f0e3c37c1..66f88a07e9 100755 --- a/challenge-250/eric-cheung/python/ch-1.py +++ b/challenge-250/eric-cheung/python/ch-1.py @@ -1,10 +1,17 @@ -## arrInt = [0, 1, 2] ## Example 1 -## arrInt = [4, 3, 2, 1] ## Example 2 -arrInt = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] ## Example 3 - -arrOutput = [nIndx for nIndx in range(len(arrInt)) if nIndx % 10 == arrInt[nIndx]] -if len(arrOutput) > 0: - print (arrOutput[0]) -else: - print (-1) +## arrInt = [6, 12, 25, 1] ## Example 1 +## arrInt = [10, 7, 31, 5, 2, 2] ## Example 2 +arrInt = [1, 2, 10] ## Example 3 + +nSum = 0 +while len(arrInt) > 0: + if len(arrInt) == 1: + nSum = nSum + arrInt[0] + del arrInt[0] + else: + nSum = nSum + int(str(arrInt[0]) + str(arrInt[-1])) + del arrInt[-1] + del arrInt[0] + +print (nSum) + diff --git a/challenge-250/eric-cheung/python/ch-2.py b/challenge-250/eric-cheung/python/ch-2.py index 43a7617ff9..a659fab6a6 100755 --- a/challenge-250/eric-cheung/python/ch-2.py +++ b/challenge-250/eric-cheung/python/ch-2.py @@ -1,9 +1,13 @@ -def GetAlphaNumLen (strInput): - return int(strInput) if strInput.isnumeric() else len(strInput) +## Remarks +## https://github.com/doocs/leetcode/blob/main/solution/1300-1399/1380.Lucky%20Numbers%20in%20a%20Matrix/README_EN.md -## arrAlphaNumStr = ["perl", "2", "000", "python", "r4ku"] ## Example 1 -arrAlphaNumStr = ["001", "1", "000", "0001"] ## Example 2 +## arrMatrix = [[3, 7, 8], [9, 11, 13], [15, 16, 17]] ## Example 1 +## arrMatrix = [[1, 10, 4, 2], [9, 3, 8, 7], [15, 16, 17, 12]] ## Example 2 +arrMatrix = [[7, 8], [1, 2]] ## Example 3 -arrOutput = [GetAlphaNumLen(strLoop) for strLoop in arrAlphaNumStr] -print (max(arrOutput)) +setRowMin = {min(rowLoop) for rowLoop in arrMatrix} +setColMax = {max(colLoop) for colLoop in zip(*arrMatrix)} + +arrLuckyNum = list(setRowMin & setColMax) ## Intersection of Two Sets +print (arrLuckyNum if len(arrLuckyNum) > 0 else -1) -- cgit