package main

import (
"fmt"
"reflect"
) func isAnagram(s string, t string) bool {
// var m1 map[string]int
// var m2 map[string]int
//map申明后默认是nil,得用make进行实例化
m1 := make(map[string]int)
m2 := make(map[string]int) for _, i := range s {
m1[string(i)]++
}
for _, j := range t {
m2[string(j)]++
}
return reflect.DeepEqual(m1, m2)
//map不能直接用“==”进行比较 } func main() {
s := "hello"
t := "lelho"
// isAnagram(s, t)
fmt.Println(isAnagram(s, t)) }

  

go语言实现leetcode-242的更多相关文章

  1. C#版[击败99.69%的提交] - Leetcode 242. 有效的同构异形词 - 题解

    C#版 - Leetcode 242. 有效的同构异形词 - 题解 Leetcode 242.Valid Anagram 在线提交: https://leetcode.com/problems/val ...

  2. 前端与算法 leetcode 242. 有效的字母异位词

    目录 # 前端与算法 leetcode 242. 有效的字母异位词 题目描述 概要 提示 解析 解法一:哈希表 解法二:数组判断字符出现次数 解法三:转换字符串 算法 传入测试用例的运行结果 执行结果 ...

  3. 使用Java+Kotlin双语言的LeetCode刷题之路(三)

    BasedLeetCode LeetCode learning records based on Java,Kotlin,Python...Github 地址 序号对应 LeetCode 中题目序号 ...

  4. 使用Java+Kotlin双语言的LeetCode刷题之路(二)

    BasedLeetCode LeetCode learning records based on Java,Kotlin,Python...Github 地址 序号对应 LeetCode 中题目序号 ...

  5. 使用Java+Kotlin双语言的LeetCode刷题之路(一)

    LeetCode learning records based on Java,Kotlin,Python...Github 地址 序号对应 LeetCode 中题目序号 1 两数之和 给定一个整数数 ...

  6. LeetCode 242. 有效的字母异位词(Valid Anagram)

    242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...

  7. 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)

    22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...

  8. LN : leetcode 242 Valid Anagram

    lc 242 Valid Anagram 242 Valid Anagram Given two strings s and t, write a function to determine if t ...

  9. LeetCode 242. Valid Anagram (验证变位词)

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  10. [LeetCode] 242. Valid Anagram 验证变位词

    Given two strings s and t , write a function to determine if t is an anagram of s. Example 1: Input: ...

随机推荐

  1. (二)Spring初步搭建、IOC创建对象

    环境准备: 见java环境搭建 新建maven项目,同时搭好项目结构,新建相应的包 Spring的初步搭建 1.导入jar包,Spring版本为5.1.10,同时导入junit包 <depend ...

  2. C++ for无限循环~

    无限循环 如果条件永远不为假,则循环将变成无限循环.for 循环在传统意义上可用于实现无限循环.由于构成循环的三个表达式中任何一个都不是必需的,您可以将某些条件表达式留空来构成一个无限循环. #inc ...

  3. Flink 历史服务与连接器

    History Server(历史服务) Flink提供了记录历史任务运行情况的服务,可用于在关闭Flink群集后依然能够查询已完成作业的相关信息. 配置: # 任务执行信息存储在hdfs目录 job ...

  4. Spring 框架介绍

    Spring 框架介绍 Spring 框架模块 Spring开发环境搭建(Eclipse) 创建一个简单的Spring应用 Spring 控制反转容器(Inversion of Control – I ...

  5. slave_net_timeout, MASTER_HEARTBEAT_PERIOD, MASTER_CONNECT_RETRY,以及 MASTER_RETRY_COUNT设置和查看

    在主从复制中,有几个参数是非常重要的,包括slave_net_timeout, MASTER_HEARTBEAT_PERIOD, MASTER_CONNECT_RETRY,以及 MASTER_RETR ...

  6. VUE中常用的一些方法

    1.获取URL中的参数 export function getUrlKey(name) { return decodeURIComponent((new RegExp('[?|&]' + na ...

  7. zabbix_server

    http://www.linuxidc.com/Linux/2014-11/109909.htm [root@localhost zabbix]# service iptables stop  关闭i ...

  8. bzoj 2306

    %%%%http://blog.csdn.net/popoqqq/article/details/43926365 #include<bits/stdc++.h> #define INF ...

  9. C++ STD Gems05

    find.find_if.find_first_of.mismatch.search.adjacent_find #include <iostream> #include <vect ...

  10. Thread.currentThread()和this的区别

    1. Thread.currentThread()可以获取当前线程的引用,一般都是在没有线程对象又需要获得线程信息时通过Thread.currentThread()获取当前代码段所在线程的引用. 2. ...