前言反转链表是程序员必备的基本素养,经常在面试、笔试的过程中出现。一直觉得反转链表实现代码不是很好理解,决定搬leetcode那道经典反转链表题出来,用十多张图去解析它,希望加深大家对链表反转的理解,谢谢阅读。leetcode的反转链表原题&答案题目描述:反转一个单链表。输入:1->2->3->4->5->NULL输出:5->4->3->2-
分类:
其他好文 时间:
2020-11-07 17:05:38
阅读次数:
14
bool recursion(int* target, int srcSize, int* src, int num, int pst){ int cnt=0,i; int oodpst=0,evenpst=srcSize/2; int arr[5001]={0}; if (srcSize<=num ...
分类:
其他好文 时间:
2020-11-07 16:40:47
阅读次数:
16
Leetcode 101 数据结构定义: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x ...
分类:
其他好文 时间:
2020-11-07 16:16:53
阅读次数:
21
int factorial(int n){ int ret=1; while(n) ret*=n--; return ret; } int paintingPlan(int n, int k){ if (k==0 || k==n*n) return 1; int blank=n*n-k,ret=0, ...
分类:
其他好文 时间:
2020-11-07 16:12:37
阅读次数:
18
# # @lc app=leetcode.cn id=70 lang=python3 # # [70] 爬楼梯 # # @lc code=start class Solution: def climbStairs(self, n: int) -> int: if n == 1: return 1 i ...
分类:
其他好文 时间:
2020-11-07 16:09:23
阅读次数:
19
int Fun(int x){ int res=0; while (x) res+=x&1,x>>=1; return res; } int Mycmp(const void* a,const void* b){ return (Fun(*(int*)a) - Fun(*(int*)b))? Fun ...
分类:
编程语言 时间:
2020-11-07 15:46:24
阅读次数:
19
Leetcode easy ListNode Leetcode 简单链表题目 21 合并两个有序链表 题目:将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 /** * Definition for singly-linked list. * publ ...
分类:
其他好文 时间:
2020-11-06 02:28:36
阅读次数:
19
Leetcode(easy Double pointer) Leetcode 双指针简单题目 26 删除排序数组中的重复项 class Solution{ public int removeDuplicates(int[] nums){ // step代表慢指针 int step = 0; // 这 ...
分类:
其他好文 时间:
2020-11-06 02:28:21
阅读次数:
24
题解:递归求左右子树的最大深度。 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { ...
分类:
其他好文 时间:
2020-11-06 01:10:43
阅读次数:
21
###题目 717. 1-bit and 2-bit Characters ###解题方法 将指针设置在第0个位置,当数组长度>1时,如果当前位置是1,就把前两个数pop掉,否则是0的话就把前1个数pop掉,遍历结束看看bits还有没有元素,有的话return True,没有就return Fals ...
分类:
其他好文 时间:
2020-11-04 19:23:49
阅读次数:
36