Swift - Beats 100% w/ Explanation + Time & Space
Approach\n- Max Number: Find first non-nine value and replace it + all other occurrences of this value w/ 9\n- Min Number: Replace first value + all other occur
# Approach\n- Max Number: Find first non-nine value and replace it + all other occurrences of this value w/ 9\n- Min Number: Replace first value + all other occurences of this value w/ 0\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    func minMaxDifference(_ num: Int) -> Int {\n        let maxNum = getMaxValueToReplace("\\(num)", num)\n        let minNum = getMinValueToReplace("\\(num)", num)\n        return maxNum - minNum\n    }\n\n    func getMaxValueToReplace(_ str: String, _ num: Int) -> Int {\n        guard let idx = str.firstIndex(where: { $0 != "9" } ) else { return num }\n        return Int(str.replacingOccurrences(of: "\\(str[idx])", with: "9"))!\n    }\n\n    func getMinValueToReplace(_ str: String, _ num: Int) -> Int {\n        guard let idx = str.firstIndex(where: { $0 != "0" } ) else { return num }\n        return Int(str.replacingOccurrences(of: "\\(str[idx])", with: "0"))!\n    }\n}\n\n```
['Swift']