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: ...
随机推荐
- 印度第一颗CPU横空出世!阵势庞大
我们忙着推进国产芯片的同时,隔壁的印度也没闲着.作为印度顶级高校的印度理工学院(IIT)之马德拉斯校区已经发布了其首颗处理器“Shakti”(代表女性力量的印度神话人物)的SDK软件开发包,并承诺会很 ...
- HDU 5495:LCS
LCS Accepts: 127 Submissions: 397 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/655 ...
- (win32)解决虚拟按键被输入法截获(转)
源博客地址:http://blog.csdn.net/kencaber/article/details/51417871 响应WM_KEYDOWN消息时发现`~快捷键无效,设置断点发现得到的按键消息根 ...
- Java Integer Addition Subtration Overflow 整数加减溢出
leetCode有道题Reverse Integer,因为int的最大值为2的31次方减一,最小值为-2的31次方. 我一开始的代码将res递归加放在try中,以为溢出会有异常,然而并没有. 因为出传 ...
- 好记性不如烂笔头--shell参数及shell判断if系列
$0 当前脚本的文件名$n 传递给脚本或函数的参数.n 是一个数字,表示第几个参数.例如,第一个参数是$1,第二个参数是$2$# 传递给脚本或函数的参数个数$* 传递给脚本或函数的所有参数$@ 传递给 ...
- 前端ajax用post方式提交json数据给后端时,网络报错 415
项目框架:spring+springmvc+mybatis 问题描述:前端ajax用post方式提交json数据给后端时,网络报错 415 前端异常信息:Failed to load resource ...
- jquery 版本冲突解决办法
<!-- 引入1.6.4版的jq --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jq ...
- Kali链接Xshell和更新源
一.Xshell首次链接kali系统中的ssh Xshell:帮助我们去连接各种服务平台,方便管理服务器,链路可以加密处理(ssh/vsftp) 1.开启kali中的ssh服务,service ssh ...
- P 1023 组个最小数
转跳点:
- 【Android】家庭记账本手机版开发报告六
一.说在前面 昨天 1.创建登入和注册界面:2.向数据库添加一张用户表 今天 用图标显示账单情况 问题 1.使用第三方库 hellochart,时添加依赖构建失败 2.在 chertFragmen ...