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的更多相关文章

  1. *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 ...

  2. [分享]一个String工具类,也许你的项目中会用得到

    每次做项目都会遇到字符串的处理,每次都会去写一个StringUtil,完成一些功能. 但其实每次要的功能都差不多: 1.判断类(包括NULL和空串.是否是空白字符串等) 2.默认值 3.去空白(tri ...

  3. Invalid prop: type check failed for prop "XXX". Expected String, got Object.

    项目是Vue的,基于elementUI的后台管理系统. Invalid prop: type check failed for prop "total". Expected Str ...

  4. [Locked] Palindrome Permutation I & II

    Palindrome Permutation I Given a string, determine if a permutation of the string could form a palin ...

  5. 人脸识别准备 -- 基于raspberry pi 3b + movidius

    最近准备系统地学习一下深度学习和TensorFlow,就以人脸识别作为目的. 十年前我做过一些图像处理相关的项目和研究,涉及到图像检索.记得当时使用的是SIFT特征提取,该特征算子能很好地抵抗图像旋转 ...

  6. 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 ...

  7. Carbon document

    <   Getting Started Docs Reference History Contribute Github Introduction The Carbon class is inh ...

  8. hdu 3392(滚动数组优化dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3392 Pie Time Limit: 6000/3000 MS (Java/Others)    Me ...

  9. OpenCV人脸识别Eigen算法源码分析

    1 理论基础 学习Eigen人脸识别算法需要了解一下它用到的几个理论基础,现总结如下: 1.1 协方差矩阵 首先需要了解一下公式: 共公式可以看出:均值描述的是样本集合的平均值,而标准差描述的则是样本 ...

随机推荐

  1. ubuntu14.04下编译支持opengl的opencv

    在学习基于opencv的AR时,编译程序遇到报错,发现opencv不支持opengl.网上原因得知,在编译opencv时,opencv2.4以后的版本中默认ENABLE_OPENGL = NO,只需要 ...

  2. cdn,wsgi框架

    CDN:分布式服务器 wsgi:http请求----wsgi----web框架

  3. 洛谷P2279 消防局的设立 [HNOI2003] 贪心

    正解:贪心 解题报告: 传送门! 这题贪心得挺显然的,,,?居然能有蓝,,,是蓝题太水了嘛,,,? 简单说下,这题一看到就能想到,对最低的没被覆盖到的点给它的祖父建一个消防局 没了? 哦这题实现还挺有 ...

  4. virtualenvwrapper 的安装和使用(转)

    原文:http://www.cnblogs.com/asmer-stone/p/5470144.html virtualenvwrapper是用来管理virtualenv的扩展包,用着很方便. 1. ...

  5. Linux替换字符串

    sed命令批量替换多个文件中的字符串: 命令:sed -i “s/原字符串/新字符串/g” `grep 原字符串 -rl 所在目录` 例如:我要把 xy 替换为 mn,执行命令: sed -i “s/ ...

  6. CentOS配置JDK环境

    1 .下载JDK,jdk1.7.0_80.gz 2. mkdir -p /usr/lib/java 3.sudo chmod -R 777 /usr/lib/java 4.tar -zxvf jdk1 ...

  7. "portrait"(竖屏) "landscape"(横屏) css设置

    取决于浏览器或者设备的方向,HTML元素总是会有"portrait"(竖屏) "landscape"(横屏) class. 你可以在css中如下使用它们: .p ...

  8. python startswith() 函数

    startswith() 作用:判断字符串是否以指定字符或子字符串开头 >>> s = "my name is ming" >>> >&g ...

  9. [py]类和实例方法/内建方法

    内建方法 dir(__builtins__) 类和实例方法对比 class person: def __init__(self, job): self.job = job name = "m ...

  10. POJ3087:Shuffle'm Up(模拟)

    http://poj.org/problem?id=3087 Description A common pastime for poker players at a poker table is to ...