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