Swift program to convert an integer to a Roman numeral — a classic LeetCode problem: "Integer to Roman" (Problem #12).
Summary by DEV Community
1 Articles
1 Articles
Swift program to convert an integer to a Roman numeral — a classic LeetCode problem: "Integer to Roman" (Problem #12).
func intToRoman(_ num: Int) -> String { let romanMap: [(symbol: String, value: Int)] = [ ("M", 1000), ("CM", 900), ("D", 500), ("CD", 400), ("C", 100), ("XC", 90), ("L", 50), ("XL", 40), ("X", 10), ("IX", 9), ("V", 5), ("IV", 4), ("I", 1) ] var number = num var result = "" for (symbol, value) in romanMap { while number >= value { result += symbol number -= value } } return result } // Example usage print(intToRoman(1994)) // Output: MCMXCIV
Coverage Details
Total News Sources1
Leaning Left0Leaning Right0Center0Last UpdatedBias DistributionNo sources with tracked biases.
Bias Distribution
- There is no tracked Bias information for the sources covering this story.
Factuality
To view factuality data please Upgrade to Premium