522. 最长特殊序列 II 给定字符串列表,你需要从它们中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些字符实现,但不能改变剩余字符的相对顺序.空序列为所有字符串的子序列,任何字符串为其自身的子序列. 输入将是一个字符串列表,输出是最长特殊序列的长度.如果最长特殊序列不存在,返回 -1 . 示例: 输入: "aba", "cdc", "eae" 输出:…
最长特殊序列II 给定字符串列表,你需要从它们中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些字符实现,但不能改变剩余字符的相对顺序.空序列为所有字符串的子序列,任何字符串为其自身的子序列. 输入将是一个字符串列表,输出是最长特殊序列的长度.如果最长特殊序列不存在,返回 -1 . 示例: 输入: "aba", "cdc", "eae" 输出: 3 提示:…
Given a binary tree, you need to find the length of Longest Consecutive Path in Binary Tree. Especially, this path can be either increasing or decreasing. For example, [1,2,3,4] and [4,3,2,1] are both considered valid, but the path [1,2,4,3] is not v…
最长特殊序列 II class Solution { boolean containsSub(String s,String p){ int i,j; for(i=0,j=0;i<p.length()&&j<s.length();j++) if(s.charAt(j)==p.charAt(i)) i++; if(i>=p.length())return true; return false; } void removeStr(String p,LinkedList<…
187. 重复的DNA序列 所有 DNA 都由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:"ACGAATTCCG".在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助. 编写一个函数来查找 DNA 分子中所有出现超过一次的 10 个字母长的序列(子串). 示例: 输入:s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT" 输出:["AAAAACCCCC", "CCCCCAAAAA&qu…
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be any subsequence of the other stri…
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should return all 5 unique BST's shown below. 解题思路: 参考Java for LeetCode 096 Unique Binary Search Trees思路,本题很容易解决.注意,…
详见:https://leetcode.com/problems/longest-uncommon-subsequence-ii/description/ C++: 方法一: class Solution { public: int findLUSlength(vector<string>& strs) { int res = -1, j = 0, n = strs.size(); for (int i = 0; i < n; ++i) { for (j = 0; j <…
761. 特殊的二进制序列 特殊的二进制序列是具有以下两个性质的二进制序列: 0 的数量与 1 的数量相等. 二进制序列的每一个前缀码中 1 的数量要大于等于 0 的数量. 给定一个特殊的二进制序列 S,以字符串形式表示.定义一个操作 为首先选择 S 的两个连续且非空的特殊的子串,然后将它们交换.(两个子串为连续的当且仅当第一个子串的最后一个字符恰好为第二个子串的第一个字符的前一个字符.) 在任意次数的操作之后,交换后的字符串按照字典序排列的最大的结果是什么? 示例 1: 输入: S = "11…
240. 搜索二维矩阵 II 编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target.该矩阵具有以下特性: 每行的元素从左到右升序排列. 每列的元素从上到下升序排列. 示例: 现有矩阵 matrix 如下: [ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19], [3, 6, 9, 16, 22], [10, 13, 14, 17, 24], [18, 21, 23, 26, 30] ] 给定 target = 5,返回 true. 给定…