Leetcode contests 95 题解
876. Middle of the Linked List 简单题,我的做法是先数下个数,然后知道中间节点是第几个了。 ~谢谢打赏~ 赏
876. Middle of the Linked List 简单题,我的做法是先数下个数,然后知道中间节点是第几个了。 ~谢谢打赏~ 赏
868. Binary Gap 简单题,就是求一个数字二进制形式中两个1的最大间隔位置,比如22的二进制0b10110,最大距离就是2,0b100001,最大距离是5。 ~谢谢打赏~ 赏
题目链接295. Find Median from Data Stream 在一个有序数组中找中位数,但需要支持再数组中添加新的元素。本来是有序里的,可以很轻易就查到中位数,但如果添加新数字后,不一定有序。如果先对数组排序,那代价就比较...
题目链接 236. Lowest Common Ancestor of a Binary Tree 根据LCA的定义,二叉树中最小公共祖先就是两个节点p和q最近的共同祖先节点,LCA的定义没什么好解释的,主要是这道题的解法。 ~谢谢打赏...
题目链接 Leetcode 4. Median of Two Sorted Arrays 题目描述很简单,就是找到两个有序数组合并后的中位数,要求时间复杂度O(log (m+n))。 ~谢谢打赏~ 赏
题目链接:19. Remove Nth Node From End of List 删除单链表中的倒数第n个节点,链表中删除节点很简单,但这道题你得先知道要删除哪个节点。在我的解法中,我先采用计数的方式来确定删除第几个节点。另外我在头节...
题目链接 Leetcode 24. Swap Nodes in Pairs 给你一个链表,交换相邻两个节点,例如给你 1->2->3->4,输出2->1->4->3。 ~谢谢打赏~ 赏
原题链接:6.ZigZag Conversion 题目名称『曲折变换』,但给的样例只有三行,看不出到底怎么样曲折变化,所以这里我再补充一个样例,大家肯定一下就懂了。 ~谢谢打赏~ 赏
题目链接 Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of...
Leetcode 582. Kill Process 好久没刷题,今天来一道比较简单的题目,如果此题作为一道面试题,可以延伸出树的遍历,栈和队列,hashmap,treemap等,还是比较能考验基础的面试题。 ~谢谢打赏~ 赏
Leetcode 114. Flatten Binary Tree to Linked List 题目意思很简单,就是把一棵二叉数转换为链表,虽然题目中没说以什么样的形式转换,但看下样例就很容易看出来,是以先序遍历的次序转换成链表。这里...
Water and Jug Problem You are given two jugs with capacities x and y litres. There is an infinite amount of water supply...
好久没刷题了,今天来俩道简单题。 Leetcode 62. Unique Paths Leetcode 63. Unique Paths II ~谢谢打赏~ 赏
题目链接:Unique Substrings in Wraparound String 这里加段英文,不是为了凑字数,而是为了让别人搜索题目的时候能搜到我的博客。。 Consider the string s to be the infin...
题目链接:368. Largest Divisible Subset Given a set of distinct positive integers, find the largest subset such that every pa...
题目链接:53.Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which has the lar...
题目链接:Super Pow Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive ...
题目链接:Combination Sum IV Given an integer array with all positive numbers and no duplicates, find the number of possible ...
题目链接:Search a 2D Matrix II Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has th...
题目链接:Search a 2D Matrix Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the f...
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. 求一个二叉搜索树的第k小值。 题目链接:htt...
Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are i...
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are...
Given a string, find the length of the longest substring without repeating characters. 原题链接:Longest Substring Without Re...