随笔分类 - leetcode
leetcode 常见题目
摘要:给你一个 m 行 n 列的矩阵 matrix ,请按照 顺时针螺旋顺序 ,返回矩阵中的所有元素。 示例 1: 输入:matrix = [[1,2,3],[4,5,6],[7,8,9]] 输出:[1,2,3,6,9,8,7,4,5] 方法一、 按照顺序四个方向,为一组循环。如果到边界,选择下一个方向做
阅读全文
摘要:(简单) 给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。 子数组 是数组中的一个连续部分。 示例 1: 输入:nums = [-2,1,-3,4,-1,2,1,-5,4] 输出:6 解释:连续子数组 [4,-1,2,1] 的和最大,为 6
阅读全文
摘要:Implement pow(x, n), which calculates x raised to the power n (i.e. xn). 方法一: 递归 public double quickMul(double x, long N) { if (N == 0) { return 1.0;
阅读全文
摘要:Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearrang
阅读全文
摘要: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 means
阅读全文
摘要:Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order. 方法: 回溯法,去重 boolean[] vis; pu
阅读全文
摘要:Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. 方法 : 回溯法。 public List<List<Int
阅读全文
摘要:Given an array of non-negative integers nums, you are initially positioned at the first index of the array. Each element in the array represents your
阅读全文
摘要:Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where: '?' Matches any single character.
阅读全文
摘要:Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. Note: You mus
阅读全文
摘要:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Input:
阅读全文
摘要:Given an unsorted integer array nums, find the smallest missing positive integer. Follow up: Could you implement an algorithm that runs in O(n) time a
阅读全文
摘要:Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numb
阅读全文
摘要:Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen nu
阅读全文
摘要:The count-and-say sequence is a sequence of digit strings defined by the recursive formula: countAndSay(1) = "1" countAndSay(n) is the way you would "
阅读全文
摘要:Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy all of the following rules: Each of the digits 1-9
阅读全文
摘要:Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the dig
阅读全文
摘要:Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if i
阅读全文
摘要:Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. If target is not found in th
阅读全文
摘要:You are given an integer array nums sorted in ascending order, and an integer target. Suppose that nums is rotated at some pivot unknown to you before
阅读全文