【leetcode】522. Longest Uncommon Subsequence II
题目如下:

解题思路:因为given list长度最多是50,我的解法就比较随意了,直接用一个嵌套的循环,判断数组中每个元素是否是其他的subsequence,最后找出不属于任何元素subsequence的最长元素即可。
代码如下:
class Solution(object):
def isSubsequence(self, a, b):
"""
:type a: str
:type b: str
:rtype: int
"""
s = b
for i in a:
inx = s.find(i)
if inx == -1:
return False
s = s[inx+1:]
return True def findLUSlength(self, strs):
"""
:type strs: List[str]
:rtype: int
"""
def cmpf(v1,v2):
return len(v2) - len(v1)
strs.sort(cmp = cmpf)
if len(strs) == 0 or len(strs[0]) == 0:
return -1
res = -1 visit = [0 for x in strs]
for i in range(len(strs)):
if visit[i] == 1:
continue
tmp = False
for j in range(len((strs))):
if i == j:
continue
tmp = self.isSubsequence(strs[i],strs[j])
if tmp == True:
visit[i] = 1 for i in xrange(len(visit)):
if visit[i] == 0:
return len(strs[i])
return -1
【leetcode】522. Longest Uncommon Subsequence II的更多相关文章
- 【LeetCode】522. Longest Uncommon Subsequence II 解题报告(Python)
[LeetCode]522. Longest Uncommon Subsequence II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemin ...
- 【LeetCode】521. Longest Uncommon Subsequence I 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【leetcode】521. Longest Uncommon Subsequence I
problem 521. Longest Uncommon Subsequence I 最长非共同子序列之一 题意: 两个字符串的情况很少,如果两个字符串相等,那么一定没有非共同子序列,反之,如果两个 ...
- 522. Longest Uncommon Subsequence II
Given a list of strings, you need to find the longest uncommon subsequence among them. The longest u ...
- 【leetcode】300.Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- 【LeetCode】516. Longest Palindromic Subsequence 最长回文子序列
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题思路 代码 刷题心得 日期 题目地址:https://le ...
- 【LeetCode】594. Longest Harmonious Subsequence 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计次数 日期 题目地址:https://leetc ...
- 【LeetCode】300. Longest Increasing Subsequence 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【leetcode】1218. Longest Arithmetic Subsequence of Given Difference
题目如下: Given an integer array arr and an integer difference, return the length of the longest subsequ ...
随机推荐
- Python 笔试集(3):编译/解释?动态/静态?强/弱?Python 是一门怎样的语言
面试题 解释/编译?动态/静态?强/弱?Python 到底是一门怎样的语言? 编译 or 解释? 编译.解释都是指将(与人类亲和的)编程语言翻译成(计算机能够理解的)机器语言(Machine code ...
- 阶段3 1.Mybatis_01.Mybatis课程介绍及环境搭建_04.mybatis概述
- RESR API (三)之Views
Class-based Views Django's class-based views are a welcome departure from the old-style views. - Rei ...
- [LeetCode] 272. Closest Binary Search Tree Value II 最近的二叉搜索树的值 II
Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...
- vim加脚本注释和文本加密
vim /etc/vimrc 一.李导版本 autocmd BufNewFile *.py,*.cc,*.sh,*.java exec ":call SetTitle()" fun ...
- TCP/IP协议-1
转载资源,链接地址https://www.cnblogs.com/evablogs/p/6709707.html
- mysql简单命令
库: 增 create database db1:新建一个默认编码的库 create database db1 charset uet8 ;建一个编码为 utf8 的库 删 drop database ...
- Datatable 中的数据查询(查询不重复记录)
http://blog.csdn.net/lovexiaoxiao/article/details/3734932 //在sql中我们使用distinct查询不重复记录 //然而我在项目中表关系 ...
- setState总结
react中的setState特点: 是异步操作函数: 组件在还没有渲染之前, this.setState 还没有被调用: 批量执行 State 转变时让 DOM 渲染更快(相对比一个一个的setSt ...
- git上传代码到code.csdn.net
国内有code.csdn.net速度很快 用git上传需要去下载git程序 很简单. 我是Windows下 先code.csdn.net创建一个项目 https://code.csdn.net/das ...