public ListNode removeNthFromEnd(ListNode head, int n) { ListNode res=new ListNode(); //删除链表节点最好要一个dummy节点 ListNode slow=res, fast=res; res.next = head; for (int i=0; i<=n; i++) fast = fast.next; while(fast!=n
publicintsingleNumber(int[]A){intones=0,twos=0;for(inti=0;i<A.length;i++){ones=(ones^A[...
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 题意分析: 求出树的最大深度。 思路分析 想求最大深度,我们只需递归左右子树找出哪个子树的深度更深即可,但由于还有根结点,所以在求出两个子树的最大深度之后还需要+1. 对根结点...
Given such a graph, write a function to find all the MHTs and return a list of their root labels. Format The graph contains n nodes which are labeled from 0 to n - 1. You will be given the number n and a list of undirected edges (each edge is a pair of la...
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, … Note: n is positive and will fit within the range of a 32-bit signed integer (n < 231). Example 1: Input: 3 Output: 3
最近完成了www.leetcode.com的online judge中151道算法题目。除各个题目有特殊巧妙的解法以外,大部分题目都是经典的算法或者数据结构,因此做了如下小结,具体的解题思路可以搜索我的博客:LeetCode题解 【作者】张昺华...
1320 Minimum Distance to Type a Word Using Two Fingers ✓ ✓ ✓ Hard 1319 Number of Operations to Make Network Connected ✓ ✓ ✓ Medium 1318 Minimum Flips to Make a OR b Equal to c ✓ ✓ ✓ Medium 1317 Convert Integer to the Sum of Two No-Zero Integers ✓ ✓ ✓...
Palindrome Number 11. Container With Most Water 13. Roman to Integer 15. 3Sum 16. 3Sum Closest 17. Letter Combinations of a Phone Number 18. 4Sum 19. Remove Nth Node From End of List 20. Valid Parentheses 21. Merge Two Sorted Lists 22. Generate Parentheses 23. Merge k Sorted Lists 24...
1339 Maximum Product of Splitted Binary Tree 47.70% Medium 1338 Reduce Array Size to The Half 69.20% Medium 1337 The K Weakest Rows in a Matrix 71.40% Easy 1336 Number of Transactions per Visit * 48.10% Hard 1335 Minimum Difficulty of a Job Schedule 58.30% Hard 1334 Find the City With th...
零、碎碎念从2020年十一月份开始,陆陆续续开始刷LeetCode,到今天(2021年4月9日)终于刷到了三百题。 因为三个原因自己想在LeetCode300题时做个小结整理一下,一方面以前听人说LeetCode刷个三百基本就可以找工作了…