随笔分类 - LeetCode
LeetCode刷题记录
摘要:Given an m x n matrix of non-negative integers representing the height of each unit cell in a continent, the "Pacific ocean" touches the left and top
阅读全文
摘要:Given an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the or
阅读全文
摘要:比较简单的一个题,但是浪费了很多时间,主要是因为刚开始的思路有一点漏洞。 Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Exa
阅读全文
摘要:Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*'
阅读全文
摘要:Sort a linked list in O(n log n) time using constant space complexity. Example 1: Input: 4->2->1->3 Output: 1->2->3->4 Example 2: Input: -1->5->3->4->
阅读全文
摘要:2020.2.6 494. Target Sum 我用的递归暴力解决的笨方法,本题有一种动态规划的好方法,但不能理解。待学习; 博客链接:https://www.cnblogs.com/qiang-wei/p/12271263.html 题目链接:https://leetcode.com/probl
阅读全文
摘要: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: Input:nums =
阅读全文
摘要:You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose o
阅读全文
摘要:Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input
阅读全文
摘要:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Input: "babad" Output:
阅读全文
摘要:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any p
阅读全文
摘要:Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. Example: Given a matrix of m x n elements (m r
阅读全文
摘要:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initia
阅读全文
摘要:Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. Example: Foll
阅读全文
摘要:class Solution { public: int trap(vector<int>& height) { int l = 0, r = height.size()-1, level = 0, water = 0; while (l < r) { int lower = height[height[l] < height[r] ? l++ : r--]; level = max(level,
阅读全文
摘要:1.顺时针: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place
阅读全文
摘要:1. Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your ma
阅读全文
摘要:1.Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where th
阅读全文
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or
阅读全文
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). Y
阅读全文