diff --git a/String/ShortestWayFormString.swift b/String/ShortestWayFormString.swift new file mode 100644 index 0000000..82dba6b --- /dev/null +++ b/String/ShortestWayFormString.swift @@ -0,0 +1,30 @@ +/** + * Question Link: https://leetcode.com/problems/shortest-way-to-form-string/ + * Primary idea: Iterate through source and consume same characters for the target + * Time Complexity: O(n), Space Complexity: O(1) + */ + +class ShortestWayFormString { + func shortestWay(_ source: String, _ target: String) -> Int { + var res = 0, idx = 0 + let s = Array(source), t = Array(target) + + while idx < t.count { + let pre = idx + + for i in 0..