2021年4月4日

摘要: 题目描述 Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space? /** * Definition for singly-linked 阅读全文
posted @ 2021-04-04 14:28 朴素贝叶斯 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 题目描述 The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ... 1 is read off as"one 1"or 11. 11 is rea 阅读全文
posted @ 2021-04-04 13:53 朴素贝叶斯 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 题目描述 给你一个链表,每 k 个节点一组进行翻转,请你返回翻转后的链表。k 是一个正整数,它的值小于或等于链表的长度。如果节点总数不是 k 的整数倍,那么请将最后剩余的节点保持原有顺序。 示例 : 给定这个链表:1->2->3->4->5 当 k = 2 时,应当返回: 2->1->4->3->5 阅读全文
posted @ 2021-04-04 12:56 朴素贝叶斯 阅读(29) 评论(0) 推荐(0) 编辑
摘要: 题目描述 Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. 阅读全文
posted @ 2021-04-04 11:51 朴素贝叶斯 阅读(23) 评论(0) 推荐(0) 编辑
摘要: 题目描述 Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4- 阅读全文
posted @ 2021-04-04 10:45 朴素贝叶斯 阅读(9) 评论(0) 推荐(0) 编辑
摘要: 题目描述 Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve 阅读全文
posted @ 2021-04-04 09:36 朴素贝叶斯 阅读(10) 评论(0) 推荐(0) 编辑
摘要: 题目描述 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。 示例 1: 输入: [1,2,3,4,5,6,7] 和 k = 3 输出: [5,6,7,1,2,3,4] 解释: 向右旋转 1 步: [7,1,2,3,4,5,6] 向右旋转 2 步: [6,7,1,2,3,4,5] 阅读全文
posted @ 2021-04-04 08:56 朴素贝叶斯 阅读(12) 评论(0) 推荐(0) 编辑
摘要: 题目描述 Implementint sqrt(int x).Compute and return the square root of x. 代码实现 根据实例,模拟最后违反循环条件时发生的情况,决定如何返回. class Solution { public: int mySqrt(int x) { 阅读全文
posted @ 2021-04-04 08:05 朴素贝叶斯 阅读(22) 评论(0) 推荐(0) 编辑
摘要: 题目描述 Implement pow(x, n). 思路 暴力方法时间复杂度为O(n),所以我们要想办法降低复杂度,运用二分的技巧,减少不必要的计算,设法降低递归调用的次数. 代码实现 class Solution { public: double myPow(double x, int n) { 阅读全文
posted @ 2021-04-04 07:01 朴素贝叶斯 阅读(31) 评论(0) 推荐(0) 编辑

2021年4月3日

摘要: 题目描述 给定不同面额的硬币和一个总金额。写出函数来计算可以凑成总金额的硬币组合数。假设每一种面额的硬币有无限个。 示例 1: 输入: amount = 5, coins = [1, 2, 5] 输出: 4 解释: 有四种方式可以凑成总金额: 5=5 5=2+2+1 5=2+1+1+1 5=1+1+ 阅读全文
posted @ 2021-04-03 23:57 朴素贝叶斯 阅读(40) 评论(0) 推荐(0) 编辑

导航