diff --git "a/exercises/chenguangjian/\347\256\200\345\215\225/\346\225\260\347\273\204\346\216\222\345\272\217/solution.java" "b/exercises/chenguangjian/\347\256\200\345\215\225/\346\225\260\347\273\204\346\216\222\345\272\217/solution.java" index 8242fd7f6ceb79412167288d41414fc444f62ae1..c8891b46973c602e2e6381d655bda9d69252e270 100644 --- "a/exercises/chenguangjian/\347\256\200\345\215\225/\346\225\260\347\273\204\346\216\222\345\272\217/solution.java" +++ "b/exercises/chenguangjian/\347\256\200\345\215\225/\346\225\260\347\273\204\346\216\222\345\272\217/solution.java" @@ -1,5 +1,41 @@ -class Solution { - public int[] frequencySort(int[] nums) { + + + +import java.util.Scanner; + +import java.util.*; +import java.util.Arrays; + + +class Main { + + public static void main(String[] args) { + + // 控制台输入 + Scanner scanner = new Scanner(System.in); + String numsStr = scanner.nextLine(); + + int[] nums = new int[]{}; + // 解析字符串,构造数组 + numsStr = numsStr.replaceAll(" ",""); + + if(!"[]".equals(numsStr)){ + String[] numsStrArr = numsStr.replaceAll("\\[", "").replaceAll("\\]", "").split("\\,"); + nums = new int[numsStrArr.length]; + for (int i = 0; i < numsStrArr.length; i++) { + nums[i] = Integer.parseInt(numsStrArr[i].trim()); + } + } + + scanner.close(); + // 调用方法 + int[] res = frequencySort(nums); + // 输出结果 + System.out.println(Arrays.toString(res)); + } + + + public static int[] frequencySort(int[] nums) { Map cnt = new HashMap(); for (int num : nums) { cnt.put(num, cnt.getOrDefault(num, 0) + 1); @@ -18,4 +54,6 @@ class Solution { } return nums; } -} \ No newline at end of file + + +}