【leetcode】1257. Smallest Common Region】的更多相关文章

题目如下: You are given some lists of regions where the first region of each list includes all other regions in that list. Naturally, if a region X contains another region Y then X is bigger than Y. Given two regions region1, region2, find out the smalle…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/description/ 题目描述 Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in…
原题链接在这里:https://leetcode.com/problems/smallest-common-region/ 题目: You are given some lists of regions where the first region of each list includes all other regions in that list. Naturally, if a region X contains another region Y then X is bigger tha…
原题 An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black pixels are connected, i.e., there is only one black region. Pixels are connected horizontally and vertically. Given the location (x, y) of one of…
题目如下: Return the lexicographically smallest subsequence of text that contains all the distinct characters of text exactly once. Example 1: Input: "cdadabcc" Output: "adbc" Example 2: Input: "abcd" Output: "abcd" Exa…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 [LeetCode] https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/ Total Accepted: 67533 Total Submissions: 178900 Difficulty: Easy 题目描述 Given a binary…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/smallest-integer-divisible-by-k/ 题目描述 Given a positive integer K, you need find the smallest positive integer N such that N is divisible b…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 题目地址:https://leetcode.com/problems/smallest-string-starting-from-leaf/ 题目描述 Given the root of a binary tree, each node has a value from 0 to 25 representing the lett…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/smallest-range-ii/description/ 题目描述 Given an array A of integers, for each integer A[i] we need to choose either x = -K or x = K, and add…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:prefix, 公共前缀,题解,leetcode, 力扣,Python, C++, Java 目录 题目描述 题目大意 解题方法 遍历前缀子串 使用set 遍历最短字符串 排序 日期 题目地址:https://leetcode.com/problems/longest-common-prefix/description/ 题目描述 Write a fun…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/smallest-range/description/ 题目描述: You have k lists of sorted integers in ascending order. Find the smallest range that includes at least one number from each…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数学计算 日期 题目地址:https://leetcode.com/problems/smallest-range-i/description/ 题目描述 Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K, and ad…
题目: Write a function to find the longest common prefix string amongst an array of strings. 思路:求最长前缀子串,假设第一个字符串是最长前缀子串,采用增强for得到数组中每个字符串,分别与第一个字符串的同一位置进行比较,有一个字符串在该位置不一致,就返回. public class Solution { public String longestCommonPrefix(String[] strs) { i…
Write a function to find the longest common prefix string amongst an array of strings. Solution: class Solution { public: string longestCommonPrefix(vector<string>& strs) { //runtime:4ms string str=""; if(strs.empty())return str; ; whi…
题目: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and w as the lowest node in T that…
Lowest Common Ancestor of a Binary Tree Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and w as th…
Lowest Common Ancestor of a Binary Search Tree Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two…
Longest Common Prefix Write a function to find the longest common prefix string amongst an array of strings. 解法一: 思路:设置一个位数记录器num,遍历所有字符串的第num位.如果都相同,则num++. 直到某字符串结束或者所有字符串的第num位不都相同,则返回[0~num-1]位,即最长公共前缀. class Solution { public: string longestComm…
Write a function to find the longest common prefix string amongst an array of strings. 题解: 简单的暴力遍历解决 class Solution { public: string longestCommonPrefix(vector<string>& strs) { int n = strs.size(); || strs[].empty()) return ""; string…
题目如下: You are given a string s, and an array of pairs of indices in the string pairs where pairs[i] = [a, b] indicates 2 indices(0-indexed) of the string. You can swap the characters at any pair of indices in the given pairs any number of times. Retu…
题目如下: In a project, you have a list of required skills req_skills, and a list of people.  The i-th person people[i] contains a list of skills that person has. Consider a sufficient team: a set of people such that for every required skill in req_skill…
题目如下: Given two strings text1 and text2, return the length of their longest common subsequence. A subsequence of a string is a new string generated from the original string with some characters(can be none) deleted without changing the relative order…
题目如下: Given a rooted binary tree, return the lowest common ancestor of its deepest leaves. Recall that: The node of a binary tree is a leaf if and only if it has no children The depth of the root of the tree is 0, and if the depth of a node is d, the…
题目如下: Given a positive integer K, you need find the smallest positive integer N such that N is divisible by K, and N only contains the digit 1. Return the length of N.  If there is no such N, return -1. Example 1: Input: 1 Output: 1 Explanation: The…
题目如下: Given the root of a binary tree, each node has a value from 0 to 25representing the letters 'a' to 'z': a value of 0 represents 'a', a value of 1 represents 'b', and so on. Find the lexicographically smallest string that starts at a leaf of thi…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力遍历 日期 题目地址:https://leetcode.com/problems/greatest-common-divisor-of-strings/ 题目描述 For strings S and T, we say "T divides S" if and only if S = T + ... + T (T concatenate…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典 日期 题目地址:https://leetcode.com/problems/find-common-characters/ 题目描述 Given an array A of strings made only from lowercase letters, return a list of all characters that show up…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/smallest-subtree-with-all-the-deepest-nodes/description/ 题目描述 Given a binary tree rooted at root, the depth of each node is the shortest d…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 正则+统计 日期 题目地址:https://leetcode.com/problems/most-common-word/description/ 题目描述 Given a paragraph and a list of banned words, return the most frequent word that is not in the li…
题目如下: For strings S and T, we say "T divides S" if and only if S = T + ... + T  (T concatenated with itself 1 or more times) Return the largest string X such that X divides str1 and X divides str2. Example 1: Input: str1 = "ABCABC", st…