Java和Python语法 发表于 2025-10-16 更新于 2026-09-08 做算法题,经常用到的语法 常用语法字符串排序123char[] charArray = str.toCharArray();Arrays.sort(charArray);String key = new String(charArray); 1''.join(sorted(element)) # 字符串sorted后 ['a', 'd', 'f', 's'] 字典操作1234567if (hashMap.containsKey(str_s)){ hashMap.get(str_s).add(str);} else { ArrayList<String> strings = new ArrayList<>(); strings.add(str); hashMap.put(str_s, strings);} 1234if t in dic: dic[t].append(element)else: dic[t] = [element] 打赏 微信支付 支付宝