LN : leetcode 242 Valid Anagram
lc 242 Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.
For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false.
analysation##
利用类似于带有26个桶的数组容器存放各个字母在字符串中出现的次数。
solution
bool isAnagram(char* s, char* t) {
int letters[26] = {0}, letters2[26] = {0};
int i, sum = 0, num = 0;
if (strlen(s) != strlen(t))
return false;
for (i = 0; i < strlen(s); i++) {
letters[s[i]-'a']++;
letters2[t[i]-'a']++;
num++;
}
for (i = 0; i < 26; i++) {
if (letters[i] == letters2[i])
sum += letters[i];
}
return (sum == num);
}
LN : leetcode 242 Valid Anagram的更多相关文章
- 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)
22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...
- [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: ...
- 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: ...
- LeetCode 242 Valid Anagram
Problem: Given two strings s and t, write a function to determine if t is an anagram of s. For examp ...
- (easy)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 ...
- Java [Leetcode 242]Valid Anagram
题目描述: Given two strings s and t, write a function to determine if t is an anagram of s. For example, ...
- 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 = & ...
- Leetcode 242 Valid Anagram pytyhon
题目: Given two strings s and t, write a function to determine if t is an anagram of s. For example,s ...
随机推荐
- 03-js变量强制转换
<html> <head> <title>js中的变量强转</title> <meta charset="UTF-8"/> ...
- 输入一个URL之后。。。
1.输入URL2.浏览器去浏览器缓存.系统缓存.路由器缓存查找缓存记录,有则直接访问URL对应的IP,无则下一步3.DNS解析URL,获得对应的IP4.浏览器通过TCP/IP三次握手连接服务器5.客户 ...
- [TypeScript] Overload a Function with TypeScript’s Overload Signatures
Some functions may have different return types depending on the types of the arguments with which th ...
- 智能社区--HI3516C可视门禁研发出来咯
铝壳.非常大气的外壳. 200W像素,HI3516C,携带server.创新的产品.欢迎交流:QQ237753582 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5u ...
- jqury-validate表单验证
首先需要引入插件:jquery.validate.js这个插件. 然后对需要验证的表单实现js: $("#add-firewalls-form").validate({ submi ...
- Oracle 远程访问配置 在 Windows Forms 和 WPF 应用中使用 FontAwesome 图标 C#反序列化XML异常:在 XML文档(0, 0)中有一个错误“缺少根元素” C#[Win32&WinCE&WM]应用程序只能运行一个实例:MutexHelper Decimal类型截取保留N位小数向上取, Decimal类型截取保留N位小数并且不进行四舍五入操作
Oracle 远程访问配置 服务端配置 如果不想自己写,可以通过 Net Manager 来配置. 以下配置文件中的 localhost 改为 ip 地址,否则,远程不能访问. 1.网络监听配置 ...
- .net mvc4 + ajaxfileupload.js 解决IE浏览器中弹出下载对话框问题
摘要:每一个人遇到的问题都不一样,在网上找了一大圈都没有解决到我的问题!由于我的环境如标题所看到的.攻克了这个问题. 主要问题:在于响应头的设置 Controller: [HttpPost] publ ...
- 特征列 属性值 获取 vowpal wabbit 生成DNN 的训练测试数据
用户特征文件 userFeature.data 每 行 代 表 一 个 用 户 的 特 征 数 据, 格 式 为: “uid|features”,uid 和 features 用竖线“|”分隔.其中 ...
- vi/vim命令
vi / vim是Unix / Linux上最常用的文本编辑器而且功能非常强大.
- ubuntu下的root的创建进入与退出
创建: 在终端中输入:sudo passwd rootEnter new UNIX password: (在这输入你的密码)Retype new UNIX password: (确定你输入的密码)pa ...