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转https的各种应用

    http://www.lccee.com/content-57.html https://www.gworg.com/ssl/127.html apach: LoadModule socache_sh ...

  2. 爬虫初识和request使用

    一.什么是爬虫 爬虫的概念: 通过编写程序,模拟浏览器上网,让其去互联网上爬取数据的过程. 爬虫的工作流程: 模拟浏览器发送请求->下载网页代码->只提取有用的数据->存放于数据库或 ...

  3. rsync常见故障

    1.1 rsync客户端执行rsync命令错误: 客户端的错误现象: [root@nfs01 tmp]# rsync -avz /etc/hosts rsync_backup@172.16.1.41: ...

  4. Arm寄存器介绍及汇编基础

    一.ARM处理器支持7种工作模式 ① 用户模式(USR): 用于正常执行程序(The normal ARM program execution state) ② 快速中断模式(FIQ): 用于高速数据 ...

  5. Kendo UI 简单使用

    1 准备工作 引入JS文件和CSS文件 <link href="js/kendoui/styles/kendo.common.min.css" rel="style ...

  6. Python-Anaconda练习candy算子用于边缘提取,再用hough变换检测直线边缘

    img: 待检测的图像. threshold: 阈值,可先项,默认为10 line_length: 检测的最短线条长度,默认为50 line_gap: 线条间的最大间隙.增大这个值可以合并破碎的线条. ...

  7. mysql 安装以及卸载 CentOS 6.9

    mysql官网下载地址:https://dev.mysql.com/downloads/mysql/ 本次操作系统是    阿里云服务器 CentOS 6.9 64位 下载得到tar 包: mysql ...

  8. 解决WebStorm/PyCharm/IDEA卡顿的问题

    问题 webstorm强大的功能就不多做介绍了.但是它的缺点也显而易见:吃内存. 电脑配置稍低一点,运行webstorm就特别容易卡顿,特别是项目比较大的时候,那卡顿得不要不要的. 在我的PC机32g ...

  9. JavaSE---反射(未完待续)

    1.概述 1.1 Java程序中许多对象在运行时会出现2种类型:编译时类型.运行时类型: eg:Person  person=new Student(); 这行代码在编译时为Person类型,运行时为 ...

  10. Django-3 视图层

    5.1 视图函数 一个视图函数,简称视图,是一个简单的Python 函数,它接受Web请求并且返回Web响应.响应可以是一张网页的HTML内容,一个重定向,一个404错误,一个XML文档,或者一张图片 ...