Home

[leetcode] 841. Keys and Rooms _ Algorithm Problem Solve for python

1. Problem 841. Keys and Rooms There are n rooms labeled from 0 to n - 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key. When you visit a room, you may find a set of distinct keys in it. Each key has a number on it, denoting which room it unlo...

Read more

[leetcode] 933. Number of Recent Calls _ Algorithm Problem Solve for python

1. Problem 933. Number of Recent Calls You have a RecentCounter class which counts the number of recent requests within a certain time frame. Implement the RecentCounter class: RecentCounter() Initializes the counter with zero recent requests. int ping(int t) Adds a new request at time t, where t represents some time in milliseconds, an...

Read more

[leetcode] 1456. Maximum Number of Vowels in a Substring of Given Length _ Algorithm Problem Solve for python

1. Problem 1456. Maximum Number of Vowels in a Substring of Given Length Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k. Vowel letters in English are ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’. Example 1: Input: s = "abciiidef", k = 3 Output: 3 Explanation: The substring "iii" contains 3 vo...

Read more

[leetcode] 206. Reverse Linked List _ Algorithm Problem Solve for python

1. Problem 206. Reverse Linked List Given the head of a singly linked list, reverse the list, and return the reversed list. Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: Input: head = [1,2] Output: [2,1] Example 3: Input: head = [] Output: [] Constraints: The number of nodes in the list is the range [0, 5000]. ...

Read more

[leetcode] 31. Next Permutation _ Algorithm Problem Solve for python

1. Problem 31. Next Permutation A permutation of an array of integers is an arrangement of its members into a sequence or linear order. For example, for arr = [1,2,3], the following are all the permutations of arr: [1,2,3], [1,3,2], [2, 1, 3], [2, 3, 1], [3,1,2], [3,2,1]. The next permutation of an array of integers is the next lexicographica...

Read more

[leetcode] 443. String Compression _ Algorithm Problem Solve for python

1. Problem 443. String Compression Given an array of characters chars, compress it using the following algorithm: Begin with an empty string s. For each group of consecutive repeating characters in chars: If the group’s length is 1, append the character to s. Otherwise, append the character followed by the group’s length. The compressed stri...

Read more

[leetcode] 21. Merge Two Sorted Lists _ Algorithm Problem Solve for python

1. Problem 21. Merge Two Sorted Lists You are given the heads of two sorted linked lists list1 and list2. Merge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists. Return the head of the merged linked list. Example 1: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4]...

Read more