Total Difference String
Total Difference Strings
给一个string列表,判断有多少个不同的string,返回个数相同的定义:字符串长度相等并从左到右,或从右往左是同样的字符 abc 和 cba 为视为相同。
采用“哈希表”来存储字符串,在O(N)的时间复杂度内完成。
#include <string>
#include <iostream>
#include <algorithm>
#include <initializer_list>
#include <unordered_map> using namespace std; class Solution
{
public:
Solution(const initializer_list<string> &il)
{
string s; for(initializer_list<string>::iterator it = il.begin(); it != il.end(); it++)
{
s = *it; reverse(s.begin(), s.end()); s = this->_sort(*it, s); m[s]++;
}
} size_t getTotalDifferenceStringNumber(){ return this->m.size(); } private:
string _sort(const string& lhs, const string& rhs)
{
if(lhs > rhs)
return rhs + lhs;
else
return lhs + rhs;
} unordered_map<string, unsigned> m = {};
}; int main()
{
Solution so( {"abc", "cba", "Aaa", "abc"} );
cout << so.getTotalDifferenceStringNumber(); return ;
}
Total Difference String的更多相关文章
- *389. Find the Difference (string + map(26)) read problems carefully
Given two strings s and t which consist of only lowercase letters. String t is generated by random s ...
- [分享]一个String工具类,也许你的项目中会用得到
每次做项目都会遇到字符串的处理,每次都会去写一个StringUtil,完成一些功能. 但其实每次要的功能都差不多: 1.判断类(包括NULL和空串.是否是空白字符串等) 2.默认值 3.去空白(tri ...
- Invalid prop: type check failed for prop "XXX". Expected String, got Object.
项目是Vue的,基于elementUI的后台管理系统. Invalid prop: type check failed for prop "total". Expected Str ...
- [Locked] Palindrome Permutation I & II
Palindrome Permutation I Given a string, determine if a permutation of the string could form a palin ...
- 人脸识别准备 -- 基于raspberry pi 3b + movidius
最近准备系统地学习一下深度学习和TensorFlow,就以人脸识别作为目的. 十年前我做过一些图像处理相关的项目和研究,涉及到图像检索.记得当时使用的是SIFT特征提取,该特征算子能很好地抵抗图像旋转 ...
- Sphinx 2.2.11-release reference manual
1. Introduction 1.1. About 1.2. Sphinx features 1.3. Where to get Sphinx 1.4. License 1.5. Credits 1 ...
- Carbon document
< Getting Started Docs Reference History Contribute Github Introduction The Carbon class is inh ...
- hdu 3392(滚动数组优化dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3392 Pie Time Limit: 6000/3000 MS (Java/Others) Me ...
- OpenCV人脸识别Eigen算法源码分析
1 理论基础 学习Eigen人脸识别算法需要了解一下它用到的几个理论基础,现总结如下: 1.1 协方差矩阵 首先需要了解一下公式: 共公式可以看出:均值描述的是样本集合的平均值,而标准差描述的则是样本 ...
随机推荐
- Gym - 101020H Weekend floyd+next_permutation
https://vjudge.net/problem/Gym-101020H 题意:正常读取方式给你一个图(双向的),然后给你f个点,让你找一条路从1到n的最短路,要求经过f个点(以任意顺序). 题解 ...
- https-->http and http-->https bitransfer
openssl s_client -connect myupload.mysite.net:443/cgi-bin/posupload.cgi -status -cert client.pem -ve ...
- Python 字典 setdefault() 方法
描述 Python 字典 setdefault() 方法和 get() 方法类似,返回指定键的值,如果键不在字典中,将会添加键并将值设置为一个指定值,默认为None. get() 和 setdefau ...
- 洛谷P3166 数三角形 [CQOI2014] 数论
正解:数论 解题报告: 传送门! 很久以前做的题了呢,,,回想方法还想了半天QAQ 然后写这题题解主要是因为看到了好像有很新颖的法子,就想着,学习一下趴,那学都学了不写博客多可惜 首先港下最常规的方法 ...
- div+css网页标准布局实例教程(一)
今天学习<十天学会web标准(div+css)>的最后一个章节,本章节把前面学习的零碎内容串联起来,组织成一个网站,将根据本人这些年来的从业经验,从建立站点到一个完整的div+css网页的 ...
- Celery配置Redis数据库保存Return结果状态
使用windows版本 1.于GitHUB下载https://github.com/ServiceStack/redis-windows Window版本,到路径: 2. 运行路径下:D:\redis ...
- 实习培训——Servlet(6)
实习培训——Servlet(6) 1 Servlet 客户端 HTTP 请求 当浏览器请求网页时,它会向 Web 服务器发送特定信息,这些信息不能被直接读取,因为这些信息是作为 HTTP 请求的头的 ...
- 关于Flag的定义
最近在维护项目的代码,发现了由于Flag不一致导致的很多问题,现在对这一问题总结. 1,flag分为两种,可以组合的和不可以组合的.可以组合的flag适合用每一位表示一个含义.不适合组合的flag适合 ...
- Java 7代码层面上的更新
Java 7已经完成的7大新功能: 1 对集合类的语言支持: 2 自动资源管理: 3 改进的通用实例创建类型推断: 4 数字字面量下划线支持: ...
- FM/FFM原理
转自https://tech.meituan.com/deep-understanding-of-ffm-principles-and-practices.html 深入FFM原理与实践 del2z, ...