*521. Longest Uncommon Subsequence I (bit manipulation 2^n)
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:
- Both strings' lengths will not exceed 100.
- 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)的更多相关文章
- Leetcode#521. Longest Uncommon Subsequence I(最长特殊序列 Ⅰ)
题目描述 给定两个字符串,你需要从这两个字符串中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些字符实现,但 ...
- 521. Longest Uncommon Subsequence I【easy】
521. Longest Uncommon Subsequence I[easy] Given a group of two strings, you need to find the longest ...
- 【leetcode】521. Longest Uncommon Subsequence I
problem 521. Longest Uncommon Subsequence I 最长非共同子序列之一 题意: 两个字符串的情况很少,如果两个字符串相等,那么一定没有非共同子序列,反之,如果两个 ...
- 521. Longest Uncommon Subsequence I - LeetCode
Question 521. Longest Uncommon Subsequence I Solution 题目大意:给两个字符串,找出非共同子串的最大长度 思路:字符串相等就返回-1,不等就返回长度 ...
- LeetCode 521 Longest Uncommon Subsequence I 解题报告
题目要求 Given a group of two strings, you need to find the longest uncommon subsequence of this group o ...
- LeetCode: 521 Longest Uncommon Subsequence I(easy)
题目: anysubsequence of the other strings. A subsequence is a sequence that can be derived from one se ...
- 【LeetCode】521. Longest Uncommon Subsequence I 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 521. Longest Uncommon Subsequence I
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- 521. Longest Uncommon Subsequence I 最长不同子数组
[抄题]: [暴力解法]: 时间分析: 空间分析: [优化后]: 时间分析: 空间分析: [奇葩输出条件]: [奇葩corner case]: [思维问题]: [一句话思路]: 两个单词的话,就是看谁 ...
随机推荐
- arraylist和linkedlist内部的实现大致是怎样的
1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构. 2.对于随机访问get和set,ArrayList优于LinkedList,因为ArrayList可以随 ...
- esper(3)-窗口&聚合分组
一.Insert and Remove Stream 1. select * from com.ebc.updatelistener.User 只输出newEvents,不会输出oldEvents.即 ...
- OS---外存分配方式
1.概述 1.1 在为文件分配外存空间时,所考虑的主要问题:如何有效利用外存空间?如何提高对文件的访问速度? 1.2 常用的外存分配方法:连续分配.链接分配.索引分配(在一个系统中,仅采用一种分配方式 ...
- 数据结构---Java---HashSet
1.概述 1.1 HashSet不是线程安全的: 1.2 当向HashSet存入元素时,调用该对象的hashCode()值,根据hashCode()值来决定元素的存储位置: 如果hashCode()值 ...
- .NET接收邮件下载邮件附件——openpop.net
使用OpenPop.Net接收邮件很方便,下面是接收下载邮件附件的代码 OpenPop.Net下载地址 https://sourceforge.net/projects/hpop/ public cl ...
- MVC 路由检测组件 Routing Debugger
组件下载地址 haacked.com 1.在mvc项目中引入组件 2.配置route规则 public static void RegisterRoutes(RouteCollection route ...
- Windows下Redis数据库管理工具(redis-desktop-manager)安装与配置(图文详解)
Redis Desktop Manager安装 Redis Desktop Manager直接下载安装就行非常简单.下载地址: 官网下载:https://redisdesktop.com/downlo ...
- jQuery源代码学习笔记_工具函数_noop/error/now/trim
jQuery源代码学习笔记_工具函数_noop/error/now/trim jquery提供了一系列的工具函数,用于支持其运行,今天主要分析noop/error/now/trim这4个函数: 1.n ...
- HDU 1045——Fire Net——————【最大匹配、构图、邻接矩阵做法】
Fire Net Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- Windows窗体应用开发1
1.Windows窗体的基本概念 2.Windows窗体应用程序 3.Windows窗体常见界面元素 4.Windows窗体中的事件处理 1.Windows窗体的基本概念 打开一个Window的系统应 ...