From e2a7867e1ab365b7bc2787f0d650c56e789a74d3 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Mon, 18 Dec 2023 13:24:11 +0000 Subject: - Added solutions by Bob Lied. - Added solutions by David Ferrone. - Added solutions by W. Luis Mochan. - Added solutions by Mark Anderson. - Added solutions by Niels van Dijke. --- challenge-248/eric-cheung/python/ch-1.py | 21 +++++++++++++++++++++ challenge-248/eric-cheung/python/ch-2.py | 13 +++++++++++++ 2 files changed, 34 insertions(+) create mode 100755 challenge-248/eric-cheung/python/ch-1.py create mode 100755 challenge-248/eric-cheung/python/ch-2.py (limited to 'challenge-248/eric-cheung/python') diff --git a/challenge-248/eric-cheung/python/ch-1.py b/challenge-248/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..6a7dab3628 --- /dev/null +++ b/challenge-248/eric-cheung/python/ch-1.py @@ -0,0 +1,21 @@ + +## Example 1 +## strInput = "loveleetcode" +## strChar = "e" + +## Example 2 +strInput = "aaab" +strChar = "b" + +arrCharIndx = [nIndx for nIndx in range(len(strInput)) if strInput[nIndx] == strChar] +arrOutput = [] + +for nIndx in range(len(strInput)): + if strInput[nIndx] == strChar: + arrOutput.append(0) + elif nIndx < arrCharIndx[0]: + arrOutput.append(arrCharIndx[0] - nIndx) + else: + arrOutput.append(min([abs(nLoop - nIndx) for nLoop in arrCharIndx])) + +print (arrOutput) diff --git a/challenge-248/eric-cheung/python/ch-2.py b/challenge-248/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..61e8e84fd1 --- /dev/null +++ b/challenge-248/eric-cheung/python/ch-2.py @@ -0,0 +1,13 @@ + +## arrMatrixInput = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]] ## Example 1 +arrMatrixInput = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] ## Example 2 + +arrMatrixOutput = [] + +for nRow in range(len(arrMatrixInput) - 1): + arrRow = [] + for nCol in range(len(arrMatrixInput[nRow]) - 1): + arrRow.append(arrMatrixInput[nRow][nCol] + arrMatrixInput[nRow][nCol + 1] + arrMatrixInput[nRow + 1][nCol] + arrMatrixInput[nRow + 1][nCol + 1]) + arrMatrixOutput.append(arrRow) + +print (arrMatrixOutput) -- cgit