LintCode-比较字符串
来源:互联网 发布:加厚行美工刀架 编辑:程序博客网 时间:2024/05/20 22:02
描述:
比较两个字符串A和B,确定A中是否包含B中所有的字符。字符串A和B中的字符都是 大写字母
样例:
给出 A = “ABCD” B = “ACD”,返回 true
给出 A = “ABCD” B = “AABC”, 返回 false
思路:
在A中寻找B中元素,匹配后A、B中的元素均变作’#’。最后检查B,
若B均为’#’,则A包含B,否则,不包含。
#ifndef C55_H#define C55_H#include<iostream>#include<string>using namespace std;class Solution {public: bool compareStrings(string A, string B) { // write your code here for (int i = 0; i <= B.size() - 1; ++i){ for (int j = 0; j <= A.size() - 1; ++j) { if (B[i] == A[j]&&B[i]!='#' ) { B[i] = '#'; A[j] = '#'; } } } for (int i = 0; i <= B.size() - 1; ++i) { if (B[i] != '#') { return false; break; } } return true; }};#endif
阅读全文
0 0
- Lintcode(2)-比较字符串
- LintCode比较字符串
- Lintcode 比较字符串
- lintcode-比较字符串-55
- LintCode 比较字符串
- Lintcode 比较字符串
- LintCode-比较字符串
- lintcode刷题--比较字符串
- LintCode 比较字符串
- Lintcode-比较字符串
- lintcode ----比较字符串
- LintCode之比较字符串
- lintCode 55:比较字符串
- LintCode : 比较字符串
- Lintcode 比较字符串
- LintCode 54 比较字符串
- LintCode-比较字符串
- lintcode -- 比较字符串
- java实现哈夫曼编码
- Qt中LineEdit的文本数字等的读取
- 块状链表---by konnyakuxzy
- ONVIF协议网络摄像机(IPC)客户端程序开发(12):读取音视频流
- 5-18
- LintCode-比较字符串
- Maven创建第一个java项目(官方教程)
- 权限问题
- Bartender2017条码打印软件破解版含注册机
- vim安装出错: sudo apt-get install vim-gtk
- JSON总结
- 442. Find All Duplicates in an Array
- 机器学习中的训练集,验证集及测试集的关系
- Mac下安装python以及jupyter notebook