JZTXT
  • 首页
  • Ai
  • Java
  • Python
  • Android
  • Mysql
  • JavaScript
  • Html
  • CSS

leetcode 12

发布时间 2023-08-23 22:13:29作者: MaoShine

image

算法介绍:

  • 哈希

  • 贪心

  • 实现代码如下

class Solution {
public:
    string intToRoman(int num) {
        // 哈希贪心
		string s[] = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
		int v[] = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
		int i = 13;
		string res = "";
		for(int i = 0;i<13;i++){
			int temp = num / v[i];
			num -= temp * v[i];
			
			for(int j = 0;j < temp;j++){
				res += s[i];
			}
		}
		return res;
    }
};
    本栏目推荐文章
  • 【LeetCode 2701. 连续递增交易】MySQL用户变量编程得到严格递增连续子序列的开始位置,结束位置,长度等统计信息
  • 【Leetcode 2474. 购买量严格增加的客户】MySQL用户变量编程解决严格递增连续子序列问题
  • 【LeetCode 2494. 合并在同一个大厅重叠的活动】MySQL用户变量编程解决区间合并问题
  • 12.弱网测试
  • 【LeetCode1747. 应该被禁止的 Leetflex 账户】MySQL用户变量编程;尝试维护一个multiset
  • 【Leetcode1949. 坚定的友谊】使用MySQL在无向图中寻找{"CompleteTripartite", {1, 1, 3}}这个pattern
  • 2024-01-12 训练总结
  • 2024.1.12
  • 2024-1-12 DAY3
  • 【LeetCode 2142. 每辆车的乘客人数 I】乘客到站等车,车到站载客。MySQL用户变量编程完成
版权声明:本网站为非赢利性站点,本网站所有内容均来源于互联网相关站点自动搜索采集信息,相关链接已经注明来源。
联系我们