随笔分类 - LeetCode
摘要:Implement a trie with insert, search, and startsWith methods. Example: Note: You may assume that all inputs are consist of lowercase letters a-z. All
阅读全文
摘要:There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prerequisites, for example to take course 0 you have to
阅读全文
摘要:Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k]
阅读全文
摘要:Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The a
阅读全文
摘要:Reverse a singly linked list. Example: Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both? 之前做到 Reve
阅读全文
摘要:Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity shou
阅读全文
摘要:Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrenc
阅读全文
摘要:Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Explanation: "aba" is also a valid answer
阅读全文
摘要:Count the number of prime numbers less than a non-negative number, n. Example 1: Input: n = 10 Output: 4 Explanation: There are 4 prime numbers less t
阅读全文
摘要:Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where: '.' Matches any single character.
阅读全文
摘要:You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, hei
阅读全文
摘要:Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6 Return: 1 --> 2
阅读全文
摘要:Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any
阅读全文
摘要:Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive intege
阅读全文
摘要:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1: Input: n = 3 Output: ["((()))","(()
阅读全文
摘要:Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i
阅读全文
摘要:Given the head of a linked list, reverse the nodes of the list k at a time, and return the modified list. k is a positive integer and is less than or
阅读全文
摘要:Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator. The integer division should tru
阅读全文
摘要:Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive. For example, given the range [5,
阅读全文
摘要:A permutation of an array of integers is an arrangement of its members into a sequence or linear order. For example, for arr = [1,2,3], the following
阅读全文