Tag: LeetCode
-
LeetCode: 198 House Robber
•
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, and the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected, and it will automatically contact the police if two adjacent…
-
LeetCode: 509 Fibonacci Number
•
The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is: F(0) = 0, F(1) = 1 F(n) = F(n – 1) + F(n – 2), for n >…
-
LeetCode: 408 Valid Word Abbreviation
•
Given a non-empty string word and an abbreviation abbr, return whether the string matches the given abbreviation. A string abbr is a valid abbreviation of word if: It can contain numbers representing how many characters to skip. The numbers should not contain leading zeros. Example: Input: word = "internationalization", abbr…
-
LeetCode: 70 Climbing Stairs
•
You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Example: Input: n = 3 Output: 3 Explanation: There are three ways to climb to the…
-
LeetCode: 130 Surrounded Regions
•
Given an m x n matrix board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured by flipping all 'O's into 'X's in that surrounded region. Example: Input: board = [ ["X","X","X","X"], ["X","O","O","X"], ["X","X","O","X"], ["X","O","X","X"] ] Output: [ ["X","X","X","X"], ["X","X","X","X"], ["X","X","X","X"], ["X","O","X","X"] ] Explanation: Surrounded…
-
LeetCode: 383 Ransom Note
•
Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise. Each letter in magazine can only be used once in ransomNote. Example: Input: ransomNote = "a", magazine = "b" Output: false Example: Input: ransomNote = "aa", magazine =…
-
LeetCode: 278 First Bad Version
•
LeetCode: 278 First Bad Version You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also…
-
LeetCode: 155 Min Stack
•
LeetCode: 155 Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) — Pushes element x onto the stack. pop() — Removes the element on the top of the stack. top() — Gets the top element. getMin() — Retrieves the minimum…
-
LeetCode: 3 Longest Substring Without Repeating Characters
•
Given a string s, find the length of the longest substring without repeating characters. Example: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Example: Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1. 问题 给定一个字符串…
-
LeetCode: 49 Group Anagrams
•
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 rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Example: Input: strs = ["eat","tea","tan","ate","nat","bat"] Output:…