Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Note: You may assume the string contain only lowercase letters. 给一个字符串,找出第一个不重复的...
/** * Return the first Uniq Char String without using Map * @param data * @return */ private String firstUniqCharString(String data) { // NULL CHECK if (data.equals("")) { return ""; } char[] strArray = data.toCharArray(); String retStr = ""; if (data.length() == 1) {...
209. First Unique Character in a String Description Find the first unique character in a given string. You can assume that there is at least ... 【LeetCode】387. First Unique Character in a String Difficulty:easy More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/firs...
class Solution { public int firstUniqChar(String s) { int ans = Integer.MAX_VALUE; for(char c='a'; c<='z';c++){ int index = s.indexOf(c); if(index!=-1&&index==s.lastIndexOf(c)){ ans = Math.min(ans,index); } } return ans==Integer.MAX_VALUE?-1:ans; } } 题目信息 ...
Given a strings, returnthe first non-repeating character in it and return its index. If it does not exist, return-1. 中文 针对给定的一个字符串 s,你需要写一个算法,返回给定字符串中不重复字符。 这个题目在随后的面试中又出来变种。 这次需要函数返回的找到的字符串,同时输入的字符串中还有大小写。
Given a string s, return the first non-repeating character in it and return its index. If it does not exist, return -1. 中文 针对给定的一个字符串 s,你需要写一个算法,返回给定字符串中不重复字符的位置(index),如果所有的字符在给定的字符串中都有重复的话,那么你应该返回 -1。 样例 下面给出...
Given a string s, return the first non-repeating character in it and return its index. If it does not exist, return -1. 中文 针对给定的一个字符串 s,你需要写一个算法,返回给定字符串中不重复字符。 这个题目在随后的面试中又出来变种。
LeetCode 387: 字符串中的第一个唯一字符 First Unique Character in a String 题目: 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。 Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1....
if (records[str.charAt(i) - 'a'] == 1) { return str.charAt(i); } } return ' '; } } 遍历一次 public class Solution { /** * @param str: str: the given string * @return: char: the first unique character in a given string ...
First Unique Character in a String Given a string, find the first non-repeating character in it and return its index. If it doesn’t exist, return -1. unique->hashset. but hashset can only do binary things, like if I find again, the only way to show I found again is remove this...