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 协方差矩阵 首先需要了解一下公式: 共公式可以看出:均值描述的是样本集合的平均值,而标准差描述的则是样本 ...
随机推荐
- hdu4027Can you answer these queries?【线段树】
A lot of battleships of evil are arranged in a line before the battle. Our commander decides to use ...
- JavaScript学习11.30
window.history:包含浏览器的历史,可以不时用window这个前缀history.back():加载历史列表的前一个URLhistory.forward():加载历史列表的后一个URLwi ...
- ArcGIS Server 内存占用相关
发布服务个数是否有上限? 不仅是服务个数,每个服务的实例数设置非常影响机器内存与CPU的占用. 发布服务时,如果服务不经常被访问,可以将最低实例数设置为0,避免后台长期占用内存. Server需要的机 ...
- 为什么使用 Redis及其产品定位(转)
原文:http://www.infoq.com/cn/articles/tq-why-choose-redis 传统MySQL+ Memcached架构遇到的问题 实际MySQL是适合进行海量数据存储 ...
- 【F12】谷歌浏览器F12前端调试工具 Console
谷歌浏览器F12前端调试工具 Console 前言 先上图:不知道有多少人发现,在浏览器开发工具的“Console”上的百度首页的关于百度招聘的信息: 今天要给大家介绍的就是是Web前端调试工具中的C ...
- laravel教程入门笔记
安装laravel框架 1.安装命令 composer create-project --prefer-dist laravel/laravel ytkah ytkah表示文件夹名,如果不写的话自动会 ...
- 总结)Nginx/LVS/HAProxy负载均衡软件的优缺点详解
总结)Nginx/LVS/HAProxy负载均衡软件的优缺点详解 PS:Nginx/LVS/HAProxy是目前使用最广泛的三种负载均衡软件,本人都在多个项目中实施过,参考了一些资料,结合自己的一些使 ...
- ROS学习笔记一(ROS的catkin工作空间)
在安装完成ROS indigo之后,需要查看环境变量是否设置正确,并通过创建一个简单的实例来验证ROS能否正常运行. 1 查看环境变量 在ROS的安装过程中,我们执行了如下命令:(此命令就是向当前用户 ...
- Jmeter接口自动化测试 (四)(持续构建)
本文转载至http://www.cnblogs.com/chengtch/p/6145867.html Jmeter是压力测试.接口测试工具,Ant是基于Java的构建工具,具有跨平台的作用,jen ...
- 实体框架 Code First
原文:https://msdn.microsoft.com/zh-cn/en-zn/data/jj591621