摘要:
题目链接 解题思路:可以定义一个node节点,然后一个cur节点,node节点先走n-1步,然后cur和node同时走,如果node->next == null了,那么cur就是被删除的节点,此时,我们用pre节点指向cur的前一个节点(node和cur在走的时候,pre也跟着走),就可以删除cur 阅读全文
posted @ 2024-12-18 10:46
ouyangxx
阅读(21)
评论(0)
推荐(0)
摘要:
题目链接 解题思路:一个简单的回溯题目。 代码 class Solution { public: map<char, string> table{ {'2', "abc"}, {'3', "def"}, {'4', "ghi"}, {'5', "jkl"}, {'6', "mno"}, {'7', 阅读全文
posted @ 2024-12-18 10:39
ouyangxx
阅读(22)
评论(0)
推荐(0)
摘要:
题目链接 解题思路:没啥可说的,按照要求一个个字符处理 代码 class Solution { public: int romanToInt(string s) { int ans = 0; int len = s.length(); map<char, int> table{ {'I', 1}, 阅读全文
posted @ 2024-12-18 09:58
ouyangxx
阅读(8)
评论(0)
推荐(0)
摘要:
题目链接 解题思路:整数转罗马数字,可以理解为一个一个「数」,有一个转换表,从高位依次往低位「数」,直接看代码更清晰 代码 class Solution { public: string intToRoman(int num) { // 转换表 vector<pair<int, string>> t 阅读全文
posted @ 2024-12-18 09:21
ouyangxx
阅读(17)
评论(0)
推荐(0)
摘要:
题目链接 解题思路:用第一个字符串的每个字符,逐个比较其他字符串,注意别越界就行 代码 class Solution { public: string longestCommonPrefix(vector<string>& strs) { string ans = ""; int len = str 阅读全文
posted @ 2024-12-18 08:57
ouyangxx
阅读(9)
评论(0)
推荐(0)

浙公网安备 33010602011771号