Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. 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 strings.

A subsequence is a sequence that can be derived from one sequence by deleting some characters without changing the order of the remaining elements. Trivially, any string is a subsequence of itself and an empty string is a subsequence of any string.

The input will be two strings, and the output needs to be the length of the longest uncommon subsequence. If the longest uncommon subsequence doesn't exist, return -1.

Example 1:

Input: "aba", "cdc"
Output: 3
Explanation: The longest uncommon subsequence is "aba" (or "cdc"),
because "aba" is a subsequence of "aba",
but not a subsequence of any other strings in the group of two strings.

Note:

  1. Both strings' lengths will not exceed 100.
  2. Only letters from a ~ z will appear in input strings.

Solution 1:

generating all the subset 2^n (using bit manipulation)  7 : 0111

Solution 2:

class Solution {
public int findLUSlength(String a, String b) {
//generate all subsequence(subset 2^n)
if(a.equals(b)) return -1;
return Math.max(a.length(), b.length());
}
}

*521. Longest Uncommon Subsequence I (bit manipulation 2^n)的更多相关文章

  1. Leetcode#521. Longest Uncommon Subsequence I(最长特殊序列 Ⅰ)

    题目描述 给定两个字符串,你需要从这两个字符串中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些字符实现,但 ...

  2. 521. Longest Uncommon Subsequence I【easy】

    521. Longest Uncommon Subsequence I[easy] Given a group of two strings, you need to find the longest ...

  3. 【leetcode】521. Longest Uncommon Subsequence I

    problem 521. Longest Uncommon Subsequence I 最长非共同子序列之一 题意: 两个字符串的情况很少,如果两个字符串相等,那么一定没有非共同子序列,反之,如果两个 ...

  4. 521. Longest Uncommon Subsequence I - LeetCode

    Question 521. Longest Uncommon Subsequence I Solution 题目大意:给两个字符串,找出非共同子串的最大长度 思路:字符串相等就返回-1,不等就返回长度 ...

  5. LeetCode 521 Longest Uncommon Subsequence I 解题报告

    题目要求 Given a group of two strings, you need to find the longest uncommon subsequence of this group o ...

  6. LeetCode: 521 Longest Uncommon Subsequence I(easy)

    题目: anysubsequence of the other strings. A subsequence is a sequence that can be derived from one se ...

  7. 【LeetCode】521. Longest Uncommon Subsequence I 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  8. 521. Longest Uncommon Subsequence I

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  9. 521. Longest Uncommon Subsequence I 最长不同子数组

    [抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: [一句话思路]: 两个单词的话,就是看谁 ...

随机推荐

  1. http文件上传/下载

    package unit; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputSt ...

  2. linux查找重复文件

    >/dev/ >/dev/null|grep 02a42c7a845094a8904f7b3faf686b81 uniq -d, --repeated only print duplica ...

  3. python搭配selenium,htmltestrunner实现自动化测试 —— (测试思路和基础步骤)

    1. 测试思路: 编写测试单例 编写测试套件,集合测试单例 集中测试测试套件 生成测试报告 补充,发送测试结果到E-mail 2. 示例 编写测试单例 编写测试套件 测试脚本程序 生成报告 发送邮件 ...

  4. oracle序列的缓存

    在高并发的数据库系统中,序列的缓存也要相应的调大.现在看看数据库自己的一个高并发序列的定义. 当我们向数据库发送一个请求时,监听接待,然后oracle会启动一个后台进程(这个进程就是通常所说的数据库并 ...

  5. 将个人博客与github关联

    目录 将个人博客与github关联 将个人博客与github关联 #基于svg <a href="https://github.com/chatlotte" class=&q ...

  6. mysql 模拟一个自增序列

    文章出处:https://sdu0rj.axshare.com/%E4%BA%8C%E7%BA%A7%E5%AE%A2%E6%88%B7%E7%AE%A1%E7%90%86.html mysql没有像 ...

  7. Unity 组件.name

    组件.name  指的是组件所在游戏对象的名字,例如: Animation m_animation; m_animation =GetComponent<Animation>(); m_a ...

  8. [API]API运用实例

    首先,在百度API:http://apistore.baidu.com/查找自己想用的api接口,例如:翻译: 利用postman工具进行测试: 返回结果为JSON字符串: { "errNu ...

  9. 关于“importer.GetNPOTScale() == TextureImporter::kNPOTKeep”问题的简单处理方法

    在运行NGUI打包图集的时候碰到下图所示的错误,这个错误导致图片无法正确的规格进行图集生成.结果是图片变成各种诡异的尺寸!! 通过关键字搜索,发现国外有讨论这个问题的解决方案: 将图片转换为textu ...

  10. ios 开发常用函数

    rand() ----随机数 abs() / labs() ----整数绝对值 fabs() / fabsf() / fabsl() ----浮点数绝对值 floor() / floorf() / f ...