lc 242 Valid Anagram


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的更多相关文章

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

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

  2. [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: ...

  3. 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 ...

  4. [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: ...

  5. 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 ...

  6. (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 ...

  7. 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, ...

  8. 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 = & ...

  9. 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  ...

随机推荐

  1. codevs——1009 产生数

    1009 产生数 2002年NOIP全国联赛普及组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 给出一个 ...

  2. Spring Cloud(7):Zuul自定义过滤器和接口限流

    上文讲到了Zuul的基本使用: https://www.cnblogs.com/xuyiqing/p/10884860.html 自定义Zuul过滤器: package org.dreamtech.a ...

  3. JDBC的数据类型

    以下内容引用自http://wiki.jikexueyuan.com/project/jdbc/data-types.html: JDBC驱动程序在将Java数据类型发送到数据库之前,会将其转换为相应 ...

  4. 使用gdb调试python程序

    参考文章:https://mozillazg.com/2017/07/debug-running-python-process-with-gdb.html https://blog.alswl.com ...

  5. ppc_85xx-gcc -shared -fPIC liberr.c -o liberr.so

    fPIC作用于编译阶段,告诉编译器产生与位置无关代码(Position-Independent Code),   则产生的代码中,没有绝对地址,所有使用相对地址.故而代码能够被载入器载入到内存的随意 ...

  6. yarn-cli 简介

    Yarn 提供了丰富的命令行命令来帮你应付你所开发的 Yarn 包的方方面面的工作,包括安装.管理.发布等等. 虽然我们在这里按照字母顺序列出了我们提供的所有命令,但是某些更常用的命令还是要着重提一下 ...

  7. 一张图搞定OAuth2.0 在Office应用中打开WPF窗体并且让子窗体显示在Office应用上 彻底关闭Excle进程的几个方法 (七)Net Core项目使用Controller之二

    一张图搞定OAuth2.0   目录 1.引言 2.OAuth2.0是什么 3.OAuth2.0怎么写 回到顶部 1.引言 本篇文章是介绍OAuth2.0中最经典最常用的一种授权模式:授权码模式 非常 ...

  8. JAVA实现N皇后问题(回溯法)

    package com.leetCode; /** * Follow up for N-Queens problem. Now, instead outputting board configurat ...

  9. CSS和JS结合控制样式

    CSS控制样式,毋庸置疑.但有时,仅靠CSS却很难控制好,比如说,页面在多种条件下进行不同的呈现:或者运行过程中,会发生变化,比如说,左侧的菜单栏收缩了,那么右侧的宽度就变大了. 就拿这个元素的wid ...

  10. mciSendString详解(转)

    做个mp3播放器,用realplay和WMP做出来的程序内存占用太大.如果你仅仅是播放MP3,建议使用API函数mciSendString,我把该函数的详细资料罗列如下供你参考.Option Expl ...