diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2023-12-18 15:26:15 -0500 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2023-12-18 15:26:15 -0500 |
| commit | f20e269818207c1e25f7c53100ee170beaa780a6 (patch) | |
| tree | 825564a39e4ed63bbab64dbc68f37ad414dedc64 /challenge-248/eric-cheung/python/ch-1.py | |
| parent | 908aa39a6d95d19cbe8f59dc56918676ccca5976 (diff) | |
| parent | 6dfa3483d23541833b24e099be6695a90445813c (diff) | |
| download | perlweeklychallenge-club-f20e269818207c1e25f7c53100ee170beaa780a6.tar.gz perlweeklychallenge-club-f20e269818207c1e25f7c53100ee170beaa780a6.tar.bz2 perlweeklychallenge-club-f20e269818207c1e25f7c53100ee170beaa780a6.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-248/eric-cheung/python/ch-1.py')
| -rwxr-xr-x | challenge-248/eric-cheung/python/ch-1.py | 21 |
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)
|
