title: Algorithm:Find first non-repeated character in an input string
body: <p>I have seen <a href="https://stackoverflow.com/questions/14511340/find-the-first-non-repeated-character-in-a-string">this</a> and <a href="https://stackoverflow.com/questions/2955586/how-to-find-first-non-repetitive-character-from-a-string">this</a> question but mine is different. I want to write an efficient code for it in java. I came up with 2 solutions:</p>
  <h2>Approach 1.</h2>
  <pre><code>find_first_reapeted(char[] input)
  {
      HashMap&lt;Character,Integer&gt; myhash = new HashMap&lt;Character,Integer&gt; ();
      for(int i=0;i&lt;input.length;i++)
      {
        if(myhash.containsKey(input[i])
            myhash.put(input[i],2); //just put 2 even if it is more than 2
        else
            myhash.put(input[i],1);
      }
      for(int i=0;i&lt;input.length;i++)
      {
        if(myhash.getValue(input[i])==1)
           return input[i];
      }
  }
  </code></pre>
  <h2>Approach 2.</h2>
  <pre><code>find_first_reapeted(char[] input)
  {
      int[] allchars = new int[26];
      for(int i=0;i&lt;input.length;i++)
      {
          allchars[input[i]-'a'] += 1;
      }
      for(int i=0;i&lt;input.length;i++)
      {
        if(allchars[input[i]-'a']==1)
           return input[i];
      }
  }
  </code></pre>
  <p>First is there any better solution? (int term of time and space complexity)?
  If not which one of the the above is better? I'm not sure about the space complexity of hashmap!</p>