761. 特殊的二进制序列 特殊的二进制序列是具有以下两个性质的二进制序列: 0 的数量与 1 的数量相等. 二进制序列的每一个前缀码中 1 的数量要大于等于 0 的数量. 给定一个特殊的二进制序列 S,以字符串形式表示.定义一个操作 为首先选择 S 的两个连续且非空的特殊的子串,然后将它们交换.(两个子串为连续的当且仅当第一个子串的最后一个字符恰好为第二个子串的第一个字符的前一个字符.) 在任意次数的操作之后,交换后的字符串按照字典序排列的最大的结果是什么? 示例 1: 输入: S = "11…
522. 最长特殊序列 II 给定字符串列表,你需要从它们中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些字符实现,但不能改变剩余字符的相对顺序.空序列为所有字符串的子序列,任何字符串为其自身的子序列. 输入将是一个字符串列表,输出是最长特殊序列的长度.如果最长特殊序列不存在,返回 -1 . 示例: 输入: "aba", "cdc", "eae" 输出:…
521. 最长特殊序列 Ⅰ 给定两个字符串,你需要从这两个字符串中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些字符实现,但不能改变剩余字符的相对顺序.空序列为所有字符串的子序列,任何字符串为其自身的子序列. 输入为两个字符串,输出最长特殊序列的长度.如果不存在,则返回 -1. 示例 : 输入: "aba", "cdc" 输出: 3 解析: 最长特殊序列可为 "a…
187. 重复的DNA序列 所有 DNA 都由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:"ACGAATTCCG".在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助. 编写一个函数来查找 DNA 分子中所有出现超过一次的 10 个字母长的序列(子串). 示例: 输入:s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT" 输出:["AAAAACCCCC", "CCCCCAAAAA&qu…
128. 最长连续序列 给定一个未排序的整数数组,找出最长连续序列的长度. 要求算法的时间复杂度为 O(n). 示例: 输入: [100, 4, 200, 1, 3, 2] 输出: 4 解释: 最长连续序列是 [1, 2, 3, 4].它的长度为 4. class Solution { public int longestConsecutive(int[] nums) { Set<Integer> numsSet = new HashSet<>(); for (Integer nu…
Special binary strings are binary strings with the following two properties: The number of 0's is equal to the number of 1's. Every prefix of the binary string has at least as many 1's as 0's. Given a special string S, a move consists of choosing two…
package kata_007_二进制序列转十进制int; /** * java8 Lambda表达式转换binary序列->十进制数 */ import java.util.ArrayList; public class ShortBinaryToDecimal { public static void main(String[] args) { ArrayList<Integer> binary = new ArrayList(); binary.add(1); binary.ad…
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers. Ensure that numbers within the set are sorted in ascending order. Example 1…
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation. For example: Given "aacecaaa", return "aaacecaaa&qu…
Given a 2D board and a list of words from the dictionary, find all words in the board. Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same le…