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. HOJ 2985 Wavio Sequence(最长递增子序列以及其O(n*logn)算法)

    Wavio Sequence My Tags (Edit) Source : UVA Time limit : 1 sec Memory limit : 32 M Submitted : 296, A ...

  2. NLP常用语料集合

    常用语料资源 下面提供一些网上能下载到的中文的好语料,供研究人员学习使用.(1).中科院自动化所的中英文新闻语料库 http://www.datatang.com/data/13484中文新闻分类语料 ...

  3. TensorFlow 的softmax实例理解

    对于理论,简单的去看一下百度上的说明,这里直接上实例,帮助理解. # softmax函数,将向量映射到0-1的范围内,P=exp(ax)/(sum(exp(a1x)+exp(a2x)+...)) in ...

  4. ICMP报文

    类型:表示ICMP消息类型 代码:表示同一消息的不同信息 其他是时间戳或者标识符及序列号 类型 编码 描述   0 0 Echo Reply 3 0 网络不可达 3 1 主机不可达 3 2 协议不可达 ...

  5. java执行Shell命令

    java程序中要执行linux命令主要依赖2个类:Process和Runtime首先看一下Process类:ProcessBuilder.start() 和 Runtime.exec 方法创建一个本机 ...

  6. Mysql中Left Join 与Right Join 与 Inner Join 与 Full Join的区别

    看看Left Join 与Right Join 与 Inner Join 与 Full Join对表进行操作后得到的结果. 在数据库中新建两张表,并插入要测试的数据. 新建表: USE [Test] ...

  7. MySQL · 功能分析 · 5.6 并行复制实现分析

    背景 我们知道MySQL的主备同步是通过binlog在备库重放进行的,IO线程把主库binlog拉过去存入relaylog,然后SQL线程重放 relaylog 中的event,然而这种模式有一个问题 ...

  8. 万恶之源 - Python数据类型二

    列表 列表的介绍  列表是python的基础数据类型之一 ,其他编程语言也有类似的数据类型. 比如JS中的数 组, java中的数组等等. 它是以[ ]括起来, 每个元素用' , '隔开而且可以存放各 ...

  9. openstack 部署笔记--nova

    控制节点 配置用户与服务 $ . admin-openrc $ openstack user create --domain default --password-prompt nova $ open ...

  10. 计划任务cmd 清理文件

    forfiles.exe /p D:\mysql-back /s /m * /d -30 /c "cmd /c del /q @path" #清理目录下创建大于30天所有类型的文件