Tag:leetcode

  • Find out the lucky number in the array

    Time:2022-12-8

    Problem Description In an array of integers, if the frequency of occurrence of an integer is equal to its numerical value, we call this integer a “lucky number”. Give you an integer array arr, please find out from it and return a lucky number. If there are multiple lucky numbers in the array, just return […]

  • leetcode 769. Max Chunks To Make Sorted

    Time:2022-12-7

    1. The main idea of ​​the topic Tags: array https://leetcode.cn/problems/max-chunks-to-make-sorted Given an integer array arr of length n, which represents the permutation of integers in the range [0, n – 1]. We split arr into chunks (ie partitions) and sort each chunk individually. After concatenating them, the result of the concatenation is the same as […]

  • leetcode 232. Implement Queue using Stacks implement queue with stack (simple)

    Time:2022-12-6

    1. The main idea of ​​the topic Tags: stacks and queues https://leetcode.cn/problems/implement-queue-using-stacks Please use only two stacks to implement a first-in-first-out queue. The queue should support all operations supported by general queues (push, pop, peek, empty): Implement the MyQueue class: void push(int x) pushes element x to the end of the queueint pop() removes and […]

  • leetcode 155. Min Stack minimum stack (medium)

    Time:2022-12-5

    1. The main idea of ​​the topic Tags: stacks and queues https://leetcode.cn/problems/min-stack Design a stack that supports push, pop, top operations, and can retrieve the smallest element in constant time. Implement the MinStack class: MinStack() // Initialize the stack object. void push(int val) // Push the element val onto the stack. void pop() // Remove […]

  • Spot the Difference

    Time:2022-12-4

    Problem Description Given two stringssandt, which contain only lowercase letters. stringtby the stringsRandomly rearrange, then add a letter in a random position. please find intThe letters to be added. Example 1: Input: s = “abcd”, t = “abcde” Output: “e” Explanation: ‘e’ is the letter that was added. Example 2: Input: s = “”, t […]

  • leetcode 20. Valid Parentheses valid parentheses (medium)

    Time:2022-12-3

    1. The main idea of ​​the topic Tags: stacks and queues https://leetcode.cn/problems/valid-parentheses Given a string s consisting only of ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘, ‘]’, determine whether the string is valid. A valid string must satisfy: An opening parenthesis must be closed with a closing parenthesis of the same type.Opening parentheses must be closed in […]

  • leetcode 739. Daily Temperatures Daily temperature (medium)

    Time:2022-12-2

    1. The main idea of ​​the topic Tags: stacks and queues https://leetcode.cn/problems/daily-temperatures Given an integer array temperatures representing daily temperatures, return an array answer , where answer[i] means that for the i-th day, the next higher temperature will appear in a few days. If the temperature doesn’t rise after that, use 0 in that place […]

  • leetcode 23. Merge k Sorted Lists Merge K ascending linked lists (difficult)

    Time:2022-12-1

    1. The main idea of ​​the topic Tags: stacks and queues https://leetcode.cn/problems/… You are given an array of linked lists, each already sorted in ascending order. Please merge all linked lists into an ascending linked list, and return the merged linked list.   Example 1: Input: lists = [[1,4,5],[1,3,4],[2,6]]Output: [1,1,2,3,4,4,5,6]Explanation: The linked list array is […]

  • leetcode 239. Sliding Window Maximum

    Time:2022-11-30

    239. Sliding Window Maximum Maximum sliding window 1. The main idea of ​​the topic Tags: deque https://leetcode.cn/problems/… You are given an integer array nums with a sliding window of size k moving from the leftmost of the array to the rightmost of the array. You can only see k numbers within the sliding window. The […]

  • The second largest number in the string of snaps

    Time:2022-11-29

    Problem Description gives you a mixed strings, please returnsmiddlesecond largestnumber, if there is no second largest number, please return-1 。 mixed stringIt consists of lowercase English letters and numbers. Example 1: Input: s = “dfa12321afd” Output: 2 Explanation: The numbers appearing in s include [1, 2, 3]. The second largest number is 2 . Example […]

  • leetcode 128. Longest Consecutive Sequence The longest continuous sequence (medium)

    Time:2022-11-28

    1. The main idea of ​​the topic https://leetcode.cn/problems/longest-consecutive-sequence Given an unsorted integer array nums, find the length of the longest sequence of consecutive numbers (it is not required that the elements of the sequence are consecutive in the original array). Please design and implement an algorithm with time complexity O(n) to solve this problem. Example […]

  • leetcode 303. Range Sum Query – Immutable area and retrieval – array immutable (simple)

    Time:2022-11-27

    1. The main idea of ​​the topic https://leetcode.cn/problems/range-sum-query-immutable Given an integer array nums, handle multiple queries of the following types: Computes the sum of nums elements between indices left and right (inclusive), where left <= rightImplement the NumArray class: NumArray(int[] nums) Initialize the object using the array numsint sumRange(int i, int j) Returns the sum […]