随笔分类 - 刷题
LeetCode、PAT的刷题笔记
摘要:Range Sum Query - Mutable Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. The update(i, val) fun
阅读全文
摘要:Additive Number Additive number is a string whose digits can form additive sequence. A valid additive sequence should contain at least three numbers.
阅读全文
摘要:Range Sum Query 2D - Immutable Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col
阅读全文
摘要:Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Input: [10,9,2,5,3,7,1
阅读全文
摘要:Game of Life According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathem
阅读全文
摘要:Ugly Number II Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example: Inpu
阅读全文
摘要:H-Index II Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a researcher, write a function to comput
阅读全文
摘要:Single Number III Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find
阅读全文
摘要:Search a 2D Matrix II Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in
阅读全文
摘要:Sliding Window Maximum Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You
阅读全文
摘要:Product of Array Except Self Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all
阅读全文
摘要:Lowest Common Ancestor of a Binary Tree Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the de
阅读全文
摘要:Kth Smallest Element in a BST Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Example 1: Input: root
阅读全文
摘要:Majority Element II Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. Note: The algorithm should run in linear
阅读全文
摘要:Summary Ranges Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: [0,1,2,4,5,7] Output: ["0->2","4->
阅读全文
摘要:Basic Calculator Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses
阅读全文
摘要:Rectangle Area Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top ri
阅读全文
摘要:Count Complete Tree Nodes Given a complete binary tree, count the number of nodes. Note: Definition of a complete binary tree from Wikipedia: In a com
阅读全文
摘要:Maximal Square Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area. Example: Input: 1 0
阅读全文
摘要:Combination Sum III Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each co
阅读全文