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. POJ3469Dual Core CPU

    题意:给你n个模块,每个模块在A核花费为ai,在B核跑花费为bi,然后由m个任务(ai,bi,wi),表示如果ai,bi不在同一个核上跑,额外的花费为wi,求最小的花费. 分析: 用最小的费用将对象划 ...

  2. Codeforces Round #335 (Div. 2) B

    B. Testing Robots time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  3. js最后深入总结

    js常用事件: click  #点击事件 hover #鼠标漂浮事件,,鼠标移到上面就触发事件 blur  #失去焦点就触发事件,多用于文本框操作 focus  #获得焦点就触发事件, change ...

  4. ubuntu下用apt-get安装lamp缺少mcrypt , curl

    用apt-get安装的LAMP环境,但安装magento报没有mcrypt和curl,   解决方法如下: curl安装: sudo apt-get install curl libcurl3 lib ...

  5. sf01_什么是数据结构

    数据结构解决什么问题 如何在计算机中存储数据和信息,采用什么样的方法和技巧加工处理这些数据,都是数据结构需要努力解决的问题. 解决问题的步骤 使用计算机解决问题的步骤:分析具体问题得到数学模型,设计解 ...

  6. 移动测试之appium+python 简单例子(五)

    # coding=utf-8 from appium import webdriver import time import unittest import os import HTMLTestRun ...

  7. hdfs shell命令及java客户端编写

    一. hdfs shell命令 可以通过hadoop fs 查看所有的shell命令及其用法. 传文件到hdfs: hadoop fs -put /home/koushengrui/Downloads ...

  8. Hive学习(二)

    1.Hive数据导入 2.Hive的数据查询 3.Hive的Java客户端和自定义函数 1.Hive数据导入 (1.1)使用Load语句导入 HiveQL中提供LOAD DATA命令,用于导入数据到H ...

  9. Mac 终端执行sql命令

    https://www.cnblogs.com/sbj-dawn/p/6905930.html. 远程登录MYSQL数据库 > mysql -u username -p -h hostname ...

  10. Murano Weekly Meeting 2015.09.15

    Meeting time: 2015.September.15th 1:00~2:00 Chairperson:  Serg Melikyan, PTL from Mirantis Meeting s ...