1.8k 2 分钟

# 引言 题目链接:https://leetcode.com/problems/integer-to-roman/description/ # 题目大意 输入一个整型数字,将这个数字转换为罗马数字 有如下约定 Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 I can be placed before V (5) and X (10) to make 4 and 9. X can be placed before L (50) and C (100) to make 40 and 90. C can be placed before D...
1.6k 2 分钟

# 引言 题目链接:https://leetcode.com/problems/roman-to-integer/description/ # 题目大意 给出一个罗马数字,将这个罗马数字转换为数字 有如下约定 Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four...
1.4k 2 分钟

# 引言 题目链接:https://leetcode.com/problems/longest-common-prefix/description/ # 题目大意 给出一串单词,编写一个函数找到这串单词的最长公共前缀 **Hint:**If there is no common prefix, return an empty string "". Example Input: ["flower","flow","flight"] Output: "fl" Input:...
3.4k 5 分钟

# 引言 题目链接:https://leetcode.com/problems/regular-expression-matching/description/ # 题目大意 给定一个输入字符,和一个匹配模式 p, 实现正则表达式的匹配,匹配模式支持 '.' 和 '*' '.' 匹配任何单个的字符 '*' 匹配前一个元素 n 次 (n>=0) 要求模式 p 的匹配覆盖整个输入字符串,而不是部分匹配 Example Input: s = "aa" p =...
816 1 分钟

# 引言 题目链接:https://leetcode.com/problems/palindrome-number/description/ # 题目大意 判断一个数字是不是回文数字。 Example Input: 121 Output: true Input: -121 Output: false Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome. # 题解 #...
2k 3 分钟

# 引言 题目链接:https://leetcode.com/problems/string-to-integer-atoi/description/ # 题目大意 实现一个 atoi 函数。输入一串字符串,扫描字符串,跳过前面的空格,直到遇上数字或正负符号才开始做转换,而再遇到非数字或字符串结束时 ('\0') 才结束转换,并将结果返回。 Example Input: "42" Output: 42 Input: "words and 987" Output: 0 Explanation: The first...
865 1 分钟

# 引言 题目链接:https://leetcode.com/problems/reverse-integer/description/ # 题目大意 给出一个 32 位整型数字 ( int32 ), 输出这个数字翻转后的数字。 Example1 Input: 123 Output: 321 Example2 Input: -123 Output: -321 Example3 Input: 120 Output: 21 **Hint** `For the purpose of this problem, assume that your function returns 0...
1.3k 2 分钟

# 引言 题目链接:https://leetcode.com/problems/zigzag-conversion/description/ # 题目大意 给出一个字符串,和一个指定行数,将字符串纵向按照 z 字形排列 (指定行数为 z 字形大小) Example s = "PAYPALISHIRING", numRows = 3 Output: "PAHNAPLSIIGYIR" Z字形排列图 P A H N A P L S I I G Y I R # 题解 # 一句话题解 一个规律题,按照 Z...
1.8k 2 分钟

# 引言 题目链接:https://leetcode.com/problems/longest-palindromic-substring/description/ # 题目大意 给出一个字符串,找出其中最长的回文字符串 (字符串最大长度为 1000) Example Input: "babad" Output: "bab" Note: "aba" is also a valid answer. # 题解 # 一句话题解 Manache Algorithm (马拉车算法), 关于算法详情 Click Here! 复杂度...
4.4k 6 分钟

# 引言 题目链接:https://leetcode.com/problems/median-of-two-sorted-arrays/description/ # 题目大意 给出两个升序的有序序列,找到两个序列合并后序列的中位数 Hint: You may assume nums1 and nums2 cannot be both empty. 官方希望复杂度为 O(log(m+n)) # 题解 对于一个长度为 n 的已排序数列 nums , 若 n 为奇数,中位数为 nums[n/2] 若 n 为偶数,则中位数 (nums[n/2-1] + nums[n/2]) / 2 # 方法一 #...