问题描述 给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点。 示例: 给定一个链表: 1->2->3->4->5, 和 n = 2. 当删除了倒数第二个节点后,链表变为 1->2->3->5.说明: 给定的 n 保证是有效的。 进阶: 你能尝试使用一趟扫描实现吗? 来源:力扣(Lee ...
分类:
其他好文 时间:
2020-07-20 22:36:05
阅读次数:
70
Description 现有 \(n\) 种颜色(不是白色)的球,每种各 \(k\) 个。将这些球排列好后,对于每种颜色,将这种颜色的最前面的球涂成白色。试问最终得到的颜色序列有多少种。 Hint $1\le n, k\le 2\times 10^3$ Solution 我们换一种理解方式理解题目: ...
分类:
其他好文 时间:
2020-07-20 15:52:04
阅读次数:
98
Count Complete Tree Nodes Given a complete binary tree, count the number of nodes. Note: Definition of a complete binary tree from Wikipedia: In a com ...
分类:
其他好文 时间:
2020-07-20 15:46:54
阅读次数:
80
题目要求 算法分析 可以用双指针法, 分别指向头尾元素,如果两元素的和大于目标,尾指针前移,如果小于目标,头指针后移,等于目标即可得答案 代码展示(C#) public class Solution { public int[] TwoSum(int[] numbers, int target) { ...
分类:
编程语言 时间:
2020-07-20 10:40:01
阅读次数:
55
10-I. 斐波拉契数列 题意:面试题10- I. 斐波那契数列 思路:最基础的动态规划题。数据量比较大的时候不能使用递归,会报StackOverFlow Exception,最优的方式是迭代计算。 class Solution { public int fib(int n) { if (n <= ...
分类:
其他好文 时间:
2020-07-19 23:20:11
阅读次数:
72
15. 二进制中1的个数 题意:面试题15. 二进制中1的个数 思路:使用位操作,每次计算给定数字的某一个二进制位上是否为1。由于1的二进制表示中,只有末位为1,其余位均为0,所以将给定的数与1进行按位与操作,即可判断其末位上的二进制位是否为1。 public class Solution { // ...
分类:
其他好文 时间:
2020-07-19 23:18:47
阅读次数:
67
class Solution { public int maxCoins(int[] nums) { int n = nums.length + 2; int[] points = new int[n]; points[0] = 1; points[n-1] = 1; for(int i = 1; ...
分类:
其他好文 时间:
2020-07-19 18:06:08
阅读次数:
64
class Solution { public List<Integer> getRow(int rowIndex) { Integer[] res = new Integer[rowIndex+1]; Arrays.fill(res,1); for(int i = 1; i <= rowIndex ...
分类:
编程语言 时间:
2020-07-19 17:46:05
阅读次数:
79
原题链接 题解 方式一:利用额外的空间 开一个额外的空间存放数据,最后再放回去 代码如下 class Solution { public: void merge(vector<int>& A, int m, vector<int>& B, int n) { int i = 0, j = 0; int ...
分类:
编程语言 时间:
2020-07-19 16:28:00
阅读次数:
60
406. 根据身高重建队列 贪心算法 思路参考:https://leetcode-cn.com/problems/queue-reconstruction-by-height/solution/gen-ju-shen-gao-zhong-jian-dui-lie-by-leetcode/ 第一次在排 ...
分类:
其他好文 时间:
2020-07-19 15:49:30
阅读次数:
63