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 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 challenge-248/eric-cheung/python/ch-1.py (limited to 'challenge-248/eric-cheung/python/ch-1.py') 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) -- cgit