Skip to content

查找字符串中出现最多的字符和个数:Ruby #2

@ben7th

Description

@ben7th
str.split('').uniq.map {|x| [x, str.count(x)]}.sort{|a,b| b[1]<=>a[1]}[0]
str = "sdsdsddssssssdd"
str.split('').uniq.map {|x| [x, str.count(x)]}.sort{|a,b| b[1]<=>a[1]}[0]
# => ["s", 9]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions