Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Linq;
- using System.Collections.Generic;
- class Solution {
- public static string[] getFrequencies(string textString) {
- SortedList<string, int> words = new SortedList<string, int>();
- StringBuilder curr = new StringBuilder();
- for (int i = 0; i < textString.Length; i++) {
- if (!Char.IsLetter(textString[i])) {
- if (curr.Length != 0) {
- string s = curr.ToString();
- if (!words.ContainsKey(s)) {
- words.Add(s, 1);
- } else {
- words[s]++;
- }
- curr.Clear();
- }
- } else {
- curr.Append(char.ToLower(textString[i]));
- }
- }
- if (curr.Length != 0) {
- string s = curr.ToString();
- if (!words.ContainsKey(s)) {
- words.Add(s, 1);
- } else {
- words[s]++;
- }
- }
- string[] ret = new string[words.Count];
- int k = 0;
- foreach (string word in words.Keys) {
- ret[k] = word + " " + words[word];
- k++;
- }
- return ret;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement