博客
关于我
LintCode 55 比较字符串(compare string)
阅读量:323 次
发布时间:2019-03-04

本文共 692 字,大约阅读时间需要 2 分钟。

描述

比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是 大写字母

在 A 中出现的 B 字符串里的字符不需要连续或者有序。

您在真实的面试中是否遇到过这个题?

样例
给出 A = “ABCD” B = “ACD”,返回 true

给出 A = “ABCD” B = “AABC”, 返回 false

# 您的提交打败了 85.20% 的提交!class Solution:    """    @param A: A string    @param B: A string    @return: if string A contains all of the characters in B return true else return false    """    def compareStrings(self, A, B):        # write your code here        for i in B:            if i in A:                A = A.replace(i, "", 1)            else:                return False        return True# debug# main = Solution()# reuslt = main.compareStrings("ABCD", "AABC")# print(result)

提交时只需要提交class类内包含的代码,# 后面的代码供在编译器中debug(调试)使用。

转载地址:http://svuh.baihongyu.com/

你可能感兴趣的文章
MySQL 存储过程参数:in、out、inout
查看>>
mysql 存储过程每隔一段时间执行一次
查看>>
mysql 存在update不存在insert
查看>>
Mysql 学习总结(86)—— Mysql 的 JSON 数据类型正确使用姿势
查看>>
Mysql 学习总结(87)—— Mysql 执行计划(Explain)再总结
查看>>
Mysql 学习总结(88)—— Mysql 官方为什么不推荐用雪花 id 和 uuid 做 MySQL 主键
查看>>
Mysql 学习总结(89)—— Mysql 库表容量统计
查看>>
mysql 实现主从复制/主从同步
查看>>
mysql 审核_审核MySQL数据库上的登录
查看>>
mysql 导入 sql 文件时 ERROR 1046 (3D000) no database selected 错误的解决
查看>>
mysql 导入导出大文件
查看>>
MySQL 导出数据
查看>>
mysql 将null转代为0
查看>>
mysql 常用
查看>>
MySQL 常用列类型
查看>>
mysql 常用命令
查看>>
Mysql 常见ALTER TABLE操作
查看>>
MySQL 常见的 9 种优化方法
查看>>
MySQL 常见的开放性问题
查看>>
Mysql 常见错误
查看>>