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. ORACLE中Drop table cascade constraints之后果.

    当你要drop一个table时,如果删除table的动作会造成trigger或constraint产生矛盾,系统会出现错误警告的讯息而不会允许执行..一个极简单的例子,例如你有一个员工基本资料表,上面 ...

  2. Oracle安装部署之linux(redhat/centos)快速安装oracle 11g rac

    安装oracle 11gR2 RAC 一.网络规划及安装虚拟主机 主机名 主机版本 Ip rac1.localdomain Redhat 6.5 RAC节点1 192.168.100.11 rac2. ...

  3. dbAdmin 不等于 root 集合中角色

    dbAdmin  root  集合中角色 use admin创建 db.createUser( { user: "tmp_rw_56756", pwd: "tmp4242 ...

  4. xshell免费下载安装使用

    下载链接:https://www.netsarang.com/zh/all-downloads/ 然后点击下载: 然后接下来这一步很关键: 点击免费授权页面,然后填完邮箱会有激活链接,然后就可以下载免 ...

  5. DLL远程注入及卸载实现

    实现win7 64位系统下dll的远程注入及卸载,尚未再其他系统测试 源码地址:https://github.com/ndhisrfzs/InjectDll

  6. java动态加载

    先贴个笔记,后续用得着再深究. package test; import java.io.File; import java.io.IOException; import java.lang.refl ...

  7. openssl配置

    1.update openssl yum update openssl 2.修改openssl配置 vim /etc/ssh/sshd_config RSAAuthentication yesPubk ...

  8. UILabel富文本 段落格式以及UILabel添加图片

    之前文本整理有一点乱,这边重新整理一下,下面是效果图,一共两个UILabel, 富文本整理: /*NSForegroundColorAttributeName设置字体颜色,对象UIColor; NSP ...

  9. OC 手势可能出现的问题

    oc手势有分別是 Tap(点一下).Pinch(二指往內或往外拨动).Rotation(旋转).Swipe(滑动,快速移动).Pan (拖移,慢速移动)以及 LongPress(长按). UITapG ...

  10. word 加载adobe acrobat ,保存word中的清晰图片

    1:先安装 adobe 并激活 https://blog.csdn.net/xintingandzhouyang/article/details/82558235 2:打开word,点击   文件&g ...