原文链接: https://leetcode-cn.com/problems/sum-lists-lcci 英文原文You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1's digit is at the head of the list. Write a …
标签详情
递归 分类
原文链接: https://leetcode-cn.com/problems/recursive-mulitply-lcci 英文原文Write a recursive function to multiply two positive integers without using the * operator. You can use addition, subtraction, and bit shifting, but you should minimize the number of t…
原文链接: https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof 中文题目输入一个链表的头节点,从尾到头反过来返回每个节点的值(用数组返回)。 示例 1: 输入:head = [1,3,2] 输出:[2,3,1] 限制: 0 <= 链表长度 <= 10000 通过代码 高赞题解方法一:递归法解题思路: 利用递归: 先走至链表末端,回溯时依次将节点值加入列表 ,这样就可以实现链表值的倒序输出。 Python …
原文链接: https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof 中文题目输入两个递增排序的链表,合并这两个链表并使新链表中的节点仍然是递增排序的。 示例1: 输入:1->2->4, 1->3->4 输出:1->1->2->3->4->4 限制: 0 <= 链表长度 <= 1000 注意:本题与主站 21 题相同:https://leetcode-cn.com/problems/merge-two-s…
原文链接: https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof 中文题目实现 pow(x, n) ,即计算 x 的 n 次幂函数(即,xn)。不得使用库函数,同时不需要考虑大数问题。 示例 1: 输入:x = 2.00000, n = 10 输出:1024.00000 示例 2: 输入:x = 2.10000, n = 3 输出:9.26100 示例 3: 输入:x = 2.00000, n = -2 输出:0.2…
原文链接: https://leetcode-cn.com/problems/zheng-ze-biao-da-shi-pi-pei-lcof 中文题目请实现一个函数用来匹配包含'. '和'*'的正则表达式。模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(含0次)。在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串"aaa"与模式"a.a"和"ab*ac*a"匹配,但与"aa.a"和"ab*a"均不匹配。 示例 1: 输入: s = "aa" p = "a"…
原文链接: https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof 中文题目定义一个函数,输入一个链表的头节点,反转该链表并输出反转后链表的头节点。 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL 限制: 0 <= 节点个数 <= 5000 注意:本题与主站 206 题相同:https://leetcode-cn.com/problems/reverse-linked-list/ …
原文链接: https://leetcode-cn.com/problems/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof 中文题目输入一个整数 n ,求1~n这n个整数的十进制表示中1出现的次数。 例如,输入12,1~12这些整数中包含1 的数字有1、10、11和12,1一共出现了5次。 示例 1: 输入:n = 12 输出:5 示例 2: 输入:n = 13 输出:6 限制: 1
原文链接: https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof 中文题目输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历结果。如果是则返回 true,否则返回 false。假设输入的数组的任意两个数字都互不相同。 参考以下这颗二叉搜索树: 5 / \ 2 6 / \ 1 3 示例 1: 输入: [1,6,3,2,5] 输出: false 示例 2: 输入: [1,3,2,6,5…
原文链接: https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof 中文题目0,1,···,n-1这n个数字排成一个圆圈,从数字0开始,每次从这个圆圈里删除第m个数字(删除后从下一个数字开始计数)。求出这个圆圈里剩下的最后一个数字。 例如,0、1、2、3、4这5个数字组成一个圆圈,从数字0开始每次删除第3个数字,则删除的前4个数字依次是2、0、4、1,因此最后剩下的数字是3。 示例 1: …
原文链接: https://leetcode-cn.com/problems/qiu-12n-lcof 中文题目求 1+2+...+n ,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。 示例 1: 输入: n = 3 输出: 6 示例 2: 输入: n = 9 输出: 45 限制: 1 <= n <= 10000 通过代码 高赞题解解题思路:本题在简单问题上做了许多限制,需要使用排除法一步步导向答案。$1+2+…+(n-1)+…
原文链接: https://leetcode-cn.com/problems/hanota-lcci 英文原文In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from…
原文链接: https://leetcode-cn.com/problems/number-of-2s-in-range-lcci 英文原文Write a method to count the number of 2s that appear in all the numbers between 0 and n (inclusive). Example: Input: 25 Output: 9 Explanation: (2, 12, 20, 21, 22, 23, 24, 25)(Note …
原文链接: https://leetcode-cn.com/problems/UHnkqh 中文题目给定单链表的头节点 head ,请反转链表,并返回反转后的链表的头节点。 示例 1: 输入:head = [1,2,3,4,5] 输出:[5,4,3,2,1] 示例 2: 输入:head = [1,2] 输出:[2,1] 示例 3: 输入:head = [] 输出:[] 提示: 链表中节点的数目范围是 [0, 5000] -5000 <= Node.val <= 5000 进阶:链表可以选用迭代或…
原文链接: https://leetcode-cn.com/problems/LGjMqU 中文题目给定一个单链表 L 的头节点 head ,单链表 L 表示为: L0 → L1 → … → Ln-1 → Ln 请将其重新排列后变为: L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → … 不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换。 示…
原文链接: https://leetcode-cn.com/problems/aMhZSa 中文题目给定一个链表的 头节点 head ,请判断其是否为回文链表。 如果一个链表是回文,那么链表节点序列从前往后看和从后往前看是相同的。 示例 1: 输入: head = [1,2,3,3,2,1] 输出: true 示例 2: 输入: head = [1,2] 输出: false 提示: 链表 L 的长度范围为 [1, 105] 0 <= node.val <= 9 进阶:能否用 O(n) 时间复杂度…
上一页
2 / 2