When my testcase is one number,the expected answer is different from my answer.Why?


  • 0
    R

    My straight way to slove this problem.

    public class Solution {
        public int firstUniqChar(String s) {
            for(int i = 0; i < s.length(); i++){
                int flag = 0;
                for(int j = 0; j < s.length(); j++){
                    if(s.charAt(i) == s.charAt(j) && j != i){
                        flag = 1;
                        break;
                    }
                }
                if(flag == 0){
                    return i;
                }
            }
            return -1;
        }
    

    When I use this code and my testcase is "1",the expected answer is different from my answer.But when my testcase is character like "a".The two answers are right.
    Can anybody tell me why?

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.