随笔分类 - 算法
本分类用于存放一些算法题,主要来源于Leetcode。
摘要:题目 Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the re
阅读全文
摘要:题目 Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties: Integers
阅读全文
摘要:题目 Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order. Example 1: Input: n = 3 Output: [[1,2,3],[8
阅读全文
摘要:题目 You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate the image in-place, which me
阅读全文
摘要:题目 Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle. In Pascal's triangle, each number is the sum of the two
阅读全文
摘要:题目 Design a HashMap without using any built-in hash table libraries. Implement the MyHashMap class: MyHashMap() initializes the object with an empty m
阅读全文
摘要:题目 Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping interv
阅读全文
摘要:题目 Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors
阅读全文
摘要:题目 Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assum
阅读全文
摘要:题目 Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each
阅读全文
摘要:题目 Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. A subarray
阅读全文
摘要:题目 Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1
阅读全文
摘要:题目 Write an algorithm to determine if a number n is happy. A happy number is a number defined by the following process: Starting with any positive int
阅读全文
摘要:题目 Given an integer array nums, design an algorithm to randomly shuffle the array. All permutations of the array should be equally likely as a result
阅读全文
摘要:题目 Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive. Example 1
阅读全文
摘要:题目 Given an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers. Return the maximum prod
阅读全文
摘要:题目 You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Retu
阅读全文
摘要:题目 Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2. You have the following three operati
阅读全文
摘要:题目 Given two strings word1 and word2, return the minimum number of steps required to make word1 and word2 the same. In one step, you can delete exactl
阅读全文
摘要:题目 Given an integer array nums, return the number of longest increasing subsequences. Notice that the sequence has to be strictly increasing. Example
阅读全文