【字符串】C023_字符串中的第一个唯一字符(map | String 自带方法)
一、题目描述 Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. s = leetcode return 0. s = loveleetcode, return 2. 二、题解 方法一:map map 对字符进行计数。 * 优化: 可用 int[] 数组代替。 public int firstUniqChar(String S) { char[] s = S.toCharArray();
下载地址
用户评论