• LeetCode题解之Find the Difference


    1、题目描述

    2、题目分析

    比较两个字符串中加入的一个字符,由于可能在字符串中加入一个已经存在的字符,因此使用hash table 去统计字符个数最好。

    3、代码

     1  char findTheDifference(string s, string t) {
     2         
     3         map<char , int> m;
     4         for( auto & c : s )
     5             m[c]++;
     6         map<char , int>mt;
     7         for( auto &c : t)
     8             mt[c]++;
     9         
    10         for( map<char,int>::iterator it = mt.begin() ; it != mt.end() ; it++ )
    11         {
    12             if( it->second != m[it->first] )
    13                 return it->first;
    14         }
    15         
    16     }
    pp
  • 相关阅读:
    2018ddctf wp
    装饰器
    python作用域
    闭包
    迭代器
    ord() expected string of length 1, but int found
    pygm2安装问题
    elf逆向入门
    【POJ
    【POJ
  • 原文地址:https://www.cnblogs.com/wangxiaoyong/p/9288958.html
Copyright © 2020-2023  润新知