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. Xshell远程连接kali,SSH服务拒绝了密码

    在kali里面/etc/ssh/目录下,修改sshd_config文件,不是ssh_config,ssh_config是针对客户端的配置文件,而sshd_config是针对服务器端的配置文件. 找到# ...

  2. Gym 101158D(暴力)

    题意:给定两个长度为N的字符串,1<=N<=4000,求满足字符串1中的某个区间所有的字母种类和个数都与字符串2中的某个区间相同最长的区间长度. 分析: 1.预处理每个串字母个数的前缀和. ...

  3. GNS3 ip route 命令解析

    ip route 120.94.0.0 255.254.0.0 172.16.252.1ip route 192.168.0.0 255.255.0.0 10.10.10.119ip route 21 ...

  4. idea开发springboot 的mysql数据库连接问题

    今天在家用idea进行springboot开发,前面一些坑相对避免了,但是到数据库这块总是连接不上,报错主要是: Access denied for user 'root'@'localhost' ( ...

  5. python计算:pi/4=1-1/3+1/5-1/7+…

    当有一项的绝对值小于10e-6停止计算 def cul() : ans = 0;add = 1 sign = 1 while(1/add>10**(-6)) : ans = ans + sign ...

  6. 解决Exception: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z

    在项目中添加src中添加NativeIO类 /** * Licensed to the Apache Software Foundation (ASF) under one * or more con ...

  7. 163-PHP 文本替换函数str_replace(四)

    <?php $str='Hello world!'; //定义源字符串 $search=array('o','l','w'); //定义将被替换的字符数组 $replace=array('1', ...

  8. 113-PHP使用instanceof判断变量是否为某个类对象

    <?php class ren{ //定义人类 } class mao{ //定义猫类 } $ren=new ren(); //实例化一个人类的对象 $mao=new mao(); //实例化一 ...

  9. 史上最好用的idea激活方法

    最近idea老出现激活一段时间然后就让重新激活的情况,每次都网上搜索一大堆激活方法,各种网址被封,各种插件不能用.就通过朋友介绍搞到一种方式,目前对于2018版本和2019版本都能激活并且正常使用.不 ...

  10. 【LeetCode】跳跃游戏II

    [问题]给定一个非负整数数组,你最初位于数组的第一个位置.数组中的每个元素代表你在该位置可以跳跃的最大长度.你的目标是使用最少的跳跃次数到达数组的最后一个位置. 示例: 输入: [,,,,] 输出: ...