aboutsummaryrefslogtreecommitdiff
path: root/challenge-248/eric-cheung/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-248/eric-cheung/python/ch-1.py')
-rwxr-xr-xchallenge-248/eric-cheung/python/ch-1.py21
1 files changed, 21 insertions, 0 deletions
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)