![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
ParadiseHeaven
Learn to Think && Ask
展开
-
LeetCode13 罗马数字转整数
题目很简单,不解释,直接上代码class Solution { public int romanToInt(String s){ Map<Character, Integer> map = new HashMap<>(); map.put('I', 1); map.put('V', 5); map.put('X', 10); map.put('L', 50); map.put('C', 100); map.put('D', 500);原创 2020-09-09 10:45:16 · 67 阅读 · 0 评论 -
LeetCode46全排列
C++中的全排列可以直接调用next_permutation()函数,Java没有此函数,手写一个作为模板给定一个没有重复数字的序列,返回其所有可能的全排列。示例:输入: [1,2,3]输出:[ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]]代码:class Solution { public List<List<Integer>> permute(int[] nums) {原创 2020-09-09 10:39:42 · 88 阅读 · 0 评论 -
LeetCode 23. 合并K个升序链表
LeetCode 23. 合并K个升序链表作为第一道AC的困难难度的题目,记录一下题目:给你一个链表数组,每个链表都已经按升序排列。 请你将所有链表合并到一个升序链表中,返回合并后的链表。示例 1: 输入:lists = [[1,4,5],[1,3,4],[2,6]] 输出:[1,1,2,3,4,4,5,6]解释:链表数组如下: [ 1->4->5, 1->3->4, 2->6 ] 将它们合并到一个有序链表中得到。1->1->2->原创 2020-09-07 10:34:22 · 114 阅读 · 0 评论 -
LeetCode 258. 各位相加
Digital rootWikipedia的解释直接上公式:class Solution { public int addDigits(int num) { if(num == 0) return 0; return 1 + ((num-1)%9); }}原创 2020-09-05 15:34:14 · 104 阅读 · 0 评论