aboutsummaryrefslogtreecommitdiff
path: root/challenge-280/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2024-07-29 11:46:29 +0100
committerMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2024-07-29 11:46:29 +0100
commit7d6e5a9e7646e9254fdbaf7f3a3cac47c567f44f (patch)
treeca8617a29d925b53219b818ada7534e89cb2786d /challenge-280/eric-cheung/python
parent5eca255ddb9d8edbf062392e471d92273e412d7d (diff)
downloadperlweeklychallenge-club-7d6e5a9e7646e9254fdbaf7f3a3cac47c567f44f.tar.gz
perlweeklychallenge-club-7d6e5a9e7646e9254fdbaf7f3a3cac47c567f44f.tar.bz2
perlweeklychallenge-club-7d6e5a9e7646e9254fdbaf7f3a3cac47c567f44f.zip
- Added solutions by Eric Cheung.
- Added solutions by Thomas Kohler. - Added solutions by PokGoPun. - Added solutions by Mark Anderson. - Added solutions by Feng Chang. - Added solutions by E. Choroba.
Diffstat (limited to 'challenge-280/eric-cheung/python')
-rwxr-xr-xchallenge-280/eric-cheung/python/ch-1.py19
-rwxr-xr-xchallenge-280/eric-cheung/python/ch-2.py14
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-280/eric-cheung/python/ch-1.py b/challenge-280/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..df33741859
--- /dev/null
+++ b/challenge-280/eric-cheung/python/ch-1.py
@@ -0,0 +1,19 @@
+
+## Ref.
+## https://leetcode.com/problems/first-letter-to-appear-twice/description/
+## https://medium.com/@ac.shreedhar/2351-first-letter-to-appear-twice-in-java-970f99e3f625
+## https://algo.monster/liteproblems/2351
+
+def GetFirstAppearTwice (strFunc):
+ arrResult = [strFunc[0]]
+ for nIndx in range(1, len(strFunc)):
+ if strFunc[nIndx] in arrResult:
+ return strFunc[nIndx]
+ arrResult.append(strFunc[nIndx])
+ return ""
+
+## strInput = "acbddbca" ## Example 1
+## strInput = "abccd" ## Example 2
+strInput = "abcdabbb" ## Example 3
+
+print (GetFirstAppearTwice (strInput))
diff --git a/challenge-280/eric-cheung/python/ch-2.py b/challenge-280/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..d7bbc31000
--- /dev/null
+++ b/challenge-280/eric-cheung/python/ch-2.py
@@ -0,0 +1,14 @@
+
+## Ref.
+## https://leetcode.ca/2022-07-26-2315-Count-Asterisks/
+
+## strInput = "p|*e*rl|w**e|*ekly|" ## Example 1
+## strInput = "perl" ## Example 2
+strInput = "th|ewe|e**|k|l***ych|alleng|e" ## Example 3
+
+if strInput.count("|") < 2:
+ print (strInput.count("*"))
+else:
+ arrSplit = strInput.split("|")
+ strResult = "".join([arrSplit[nIndx] for nIndx in range(len(arrSplit)) if nIndx % 2 == 0])
+ print (strResult.count("*"))