leetcode
leetcode copied to clipboard
Provide all my solutions and explanations in Chinese for all the Leetcode coding problems.
Given a string `s` which consists of lowercase or uppercase letters, return _the length of the longest palindrome_ that can be built with those letters. Letters are case sensitive, for...
[请点击下方图片观看讲解视频](https://www.youtube.com/watch?v=g87mM5FJYqw) [Click below image to watch YouTube Video](https://www.youtube.com/watch?v=g87mM5FJYqw) [](https://www.youtube.com/watch?v=g87mM5FJYqw) Given an integer array `nums` of length `n` and an integer `target`, find three integers in `nums` such that the sum...
Given an integer array `nums`, return the number of range sums that lie in `[lower, upper]` inclusive. Range sum `S(i, j)` is defined as the sum of the elements in ...
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Example 1: Input: [3,2,1,5,6,4]...
Sort a linked list in _O_ ( _n_ log _n_ ) time using constant space complexity. Example 1: Input: 4->2->1->3 Output: 1->2->3->4 Example 2: Input: -1->5->3->4->0 Output: -1->0->3->4->5 常见排序方法有很多,插入排序,选择排序,堆排序,快速排序,冒泡排序,归并排序,桶排序等等。。它们的时间复杂度不尽相同,而这里题目限定了时间必须为O(nlgn),符合要求只有快速排序,归并排序,堆排序,而根据单链表的特点,最适于用归并排序。为啥呢?这是由于链表自身的特点决定的,由于不能通过坐标来直接访问元素,所以快排什么的可能不太容易实现(但是被评论区的大神们打脸,还是可以实现的),堆排序的话,如果让新建结点的话,还是可以考虑的,若只能交换结点,最好还是不要用。而归并排序(又称混合排序)因其可以利用递归来交换数字,天然适合链表这种结构。归并排序的核心是一个 merge()...
You are given a string `s` containing lowercase letters and an integer `k`. You need to : * First, change some characters of `s` to other lowercase English letters. *...
Suppose an array of length `n` sorted in ascending order is rotated between `1` and `n` times. For example, the array `nums = [0,1,2,4,5,6,7]` might become: * `[4,5,6,7,0,1,2]` if it...
Implement a basic calculator to evaluate a simple expression string. The expression string may contain open `(` and closing parentheses `)`, the plus `+` or minus sign `-`, non-negative integers...
Return the length of the shortest, non-empty, contiguous subarray of `A` with sum at least `K`. If there is no non-empty subarray with sum at least `K`, return `-1`. Example...
A peak element is an element that is strictly greater than its neighbors. Given an integer array `nums`, find a peak element, and return its index. If the array contains...