go语言实现leetcode-242
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的更多相关文章
- C#版[击败99.69%的提交] - Leetcode 242. 有效的同构异形词 - 题解
C#版 - Leetcode 242. 有效的同构异形词 - 题解 Leetcode 242.Valid Anagram 在线提交: https://leetcode.com/problems/val ...
- 前端与算法 leetcode 242. 有效的字母异位词
目录 # 前端与算法 leetcode 242. 有效的字母异位词 题目描述 概要 提示 解析 解法一:哈希表 解法二:数组判断字符出现次数 解法三:转换字符串 算法 传入测试用例的运行结果 执行结果 ...
- 使用Java+Kotlin双语言的LeetCode刷题之路(三)
BasedLeetCode LeetCode learning records based on Java,Kotlin,Python...Github 地址 序号对应 LeetCode 中题目序号 ...
- 使用Java+Kotlin双语言的LeetCode刷题之路(二)
BasedLeetCode LeetCode learning records based on Java,Kotlin,Python...Github 地址 序号对应 LeetCode 中题目序号 ...
- 使用Java+Kotlin双语言的LeetCode刷题之路(一)
LeetCode learning records based on Java,Kotlin,Python...Github 地址 序号对应 LeetCode 中题目序号 1 两数之和 给定一个整数数 ...
- LeetCode 242. 有效的字母异位词(Valid Anagram)
242. 有效的字母异位词 LeetCode242. Valid Anagram 题目描述 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的一个字母异位词. 示例 1: 输入: s ...
- 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)
22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...
- 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 ...
- 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 ...
- [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: ...
随机推荐
- arduino中的serial .available()和serial.read()
Serial.available() 的意思是:返回串口缓冲区中当前剩余的字符个数.一般用这个函数来判断串口的缓冲区有无数据,当Serial.available()>0时,说明串口接收到了数据, ...
- xv6 锁
在xv6 中锁对象是 spinlock,spinlock中的locked为1的时候表示被占用,为0的时候锁空闲. struct spinlock { uint locked; // Is the lo ...
- error LNK2019: 无法解析的外部符号……
在VS中开发程序的时候遇到一个问题,应该算是比较常见,所以记录下. 在编译程序的时候遇到一个错误,大致提示如下: "error LNK2019: 无法解析的外部符号--" 遇到这个 ...
- 在 Windows 系统上安装 Jekyll
目录 安装 Ruby 环境 用 Bundler 安装 Jekyll 本文是写给完全未用过 Ruby 乃至命令行工具者的.对于一般的开发者,Jekyll 官方文档的相关内容已然足够. 本文为钱院学辅技术 ...
- 002、将mysql用作一个简单的计算器
SELECT PI( ), , ( ) ; 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢.
- eclipse 项目启动不了问题
有可能是因为dubugger 打多了,所有启动不起来 解决方案:window——show view ——other....——breakpoints去除所有断点
- kafka 相关命令 偏移重置
kafka官方文档 https://kafka.apache.org/documentation.html#quickstart kafka 安装文档 https://www.jianshu.com/ ...
- 【pwnable.kr】fb
这是pwnable.kr的签到题,记录pwn入门到放弃的第一篇. ssh fd@pwnable.kr -p2222 (pw:guest) 题目很简单,登录上了ssh后,发现了3个文件:fd,fd.c, ...
- 数据备份 rsyncd服务器
web服务器传文件到备份服务器: 一. rsync备份服务器,yum install -y rsync makdir /etc/rsyncd touch /etc/rsyncd/rsyncd.conf ...
- Toolbar中系统自带返回键(setDisplayHomeAsUpEnabled)与Toolbar本身的inflateMenu冲突问题
在APP的Toolbar中可以设置inflateMenu来添加右上角菜单栏,但是我又同时想用系统自带的左侧返回键,随之也产生了问题:右上角的inflateMenu会不生效,即不会产生菜单按钮,查阅资料 ...