随笔分类 - 算法题
摘要:Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element.
阅读全文
摘要:Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A. You may re
阅读全文
摘要:Given an integer, write a function to determine if it is a power of two. Example 1: Example 2: Input: 5 Output: false判断一个数是否为2的次幂,偶然发现3年前做这道题就是很简单的循环对
阅读全文
摘要:Every email consists of a local name and a domain name, separated by the @ sign. For example, in alice@leetcode.com, alice is the local name, and leet
阅读全文
摘要:International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "b" map
阅读全文
摘要:Reverse a singly linked list. Example: Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both? 反转单链表,看到我
阅读全文
摘要:Given a linked list, swap every two adjacent nodes and return its head. Example: Note: Your algorithm should use only constant extra space. You may no
阅读全文
摘要:Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be
阅读全文
摘要:You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need t
阅读全文
摘要:Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k. Example 1: Note: 解法一:利用s
阅读全文
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. Follow up:Can you
阅读全文
摘要:Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space? 经典问题,判断一个单向链表是否有环,快慢指针,有相遇即有环。
阅读全文
摘要:Given a non-empty array of integers, return the k most frequent elements. Example 1: Example 2: Input: nums = [1], k = 1 Output: [1] Example 2: Note:
阅读全文
摘要:Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer
阅读全文
摘要:Given a positive integer N, find and return the longest distance between two consecutive 1's in the binary representation of N. If there aren't two co
阅读全文
摘要:This question is the same as "Max Chunks to Make Sorted" except the integers of the given array are not necessarily distinct, the input array could be
阅读全文
摘要:Given an array arr that is a permutation of [0, 1, ..., arr.length - 1], we split the array into some number of "chunks" (partitions), and individuall
阅读全文
摘要:Given a string S, check if the letters can be rearranged so that two characters that are adjacent to each other are not the same. If possible, output
阅读全文
摘要:A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element. Now given an M x N matrix, return True if and only if the m
阅读全文
摘要:Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: "Gold Medal", "Sil
阅读全文