求字母出现的最大次数

javascript实现

function getMaxCharNum(str) {
    var arr = str.split(‘‘),hash = {},max = 0,maxItem;
    arr.forEach(function(item){
        if(hash[item]){
            hash[item]++;
        }
        else{
            hash[item]=1;
        }
        if(max < hash[item]){
            max = hash[item];
            maxItem = item;
        }
    });
    return {
        count:max,
        item:maxItem,
        hash:hash
    }
}
时间: 2024-10-08 10:34:29

求字母出现的最大次数的相关文章

数组-10. 求整数序列中出现次数最多的数

数组-10. 求整数序列中出现次数最多的数(15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 张彤彧(浙江大学) 本题要求统计一个整型序列中出现次数最多的整数及其出现次数. 输入格式: 输入在一行中给出序列中整数个数N(0<N<=1000),以及N个整数.数字间以空格分隔. 输出格式: 在一行中输出出现次数最多的整数及其出现次数,数字间以空格分隔.题目保证这样的数字是唯一的. 输入样例: 10 3 2 -1 5 3 4 3

多个字符串数组求相同数据及出现次数

String[] str = {"12","121"}; String[] str1 = {"12","121"}; String[] str2 = {"12","121","122"}; String[] str3 = {"123","1234","125","126","11

求每个字符串出现的次数

//求每个字符串出现的次数 $str="sdfgfdas323344##$\$fdsdfg*$**$*$**$$443563536254fas"; //解法一 $arr = str_split($str); $arr = array_count_values($arr); arsort($arr); print_r($arr); echo '<br>'; //解法二 $arr = str_split($str); $con = array(); foreach ($arr

7-6 求整数序列中出现次数最多的数 (15 分)

7-6 求整数序列中出现次数最多的数 (15 分) 本题要求统计一个整型序列中出现次数最多的整数及其出现次数. 输入格式: 输入在一行中给出序列中整数个数N(0<N≤1000),以及N个整数.数字间以空格分隔. 输出格式: 在一行中输出出现次数最多的整数及其出现次数,数字间以空格分隔.题目保证这样的数字是唯一的. 输入样例: 10 3 2 -1 5 3 4 3 0 3 2 输出样例: 3 4 s = input().split()[1:] count_max = 0 for i in set(s

js 求字符串某个字母出现的最大次数

<!DOCTYPE HTML><html><head>    <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Max_val</title> </head><body>    <div class="">    </div> &

[LeetCode169]Majority Element求一个数组中出现次数大于n/2的数

题目: Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element always exist in the array. 思路:可以利用Dictionary将数组中每个数

Poj1961--Period(Kmp, Next数组求循环节长度 &amp;&amp; 出现次数)

Period Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 14657   Accepted: 6967 Description For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the

POJ 2299-Ultra-QuickSort(归并排序求相邻元素的交换次数)

Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 43816   Accepted: 15979 Description In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swappin

POJ 题目 3693 Maximum repetition substring(后缀数组+RMQ+枚举求最小字典序的重复次数最多的子串)

Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8067   Accepted: 2463 Description The repetition number of a string is defined as the maximum number R such that the string can be partitioned into R same conse