title: Increasing the hashmap value if the key already exists
body: <p>I am not sure why the value doesn't increase in my code when the code already exists. Any hint is really appreciated:</p>
  
  <pre><code>import java.util.HashMap;
  public class MajorityElement {
  
      public int majorityElement(int[] nums) {
          int halfSize = nums.length/2;
          int temp=0;
          int majorityValue=0;
          HashMap&lt;Integer, Integer&gt; valuesMap = new HashMap&lt;&gt;();
  
          for (int i = 0; i &lt; nums.length; i++) {
              if (valuesMap.containsValue(nums[i])) {
                  temp=valuesMap.get(nums[i]);
                  valuesMap.put(nums[i], temp++);
              } else {
                  valuesMap.put(nums[i], 1);
              }
          }
          for (Integer key : valuesMap.keySet()){
              if (valuesMap.get(key)&gt;= halfSize){
                  majorityValue=key;
              }
          }
          return majorityValue;
  
      }
      public static void main(String[] argc){
          MajorityElement majority=new MajorityElement();
          int[] sampleArray={1,4,6,8,8,9,8,8,0,8};
          int majorityRes=majority.majorityElement(sampleArray);
          System.out.println("majority value is = [" + majorityRes + "]");
          return;
      }
  }
  </code></pre>
  
  <p>UPDATE: I changed my code to </p>
  
  <pre><code>for (int i = 0; i &lt; nums.length; i++) {
              if (valuesMap.containsValue(nums[i])) {
               //   temp=valuesMap.get(nums[i]);
                  valuesMap.put(nums[i], valuesMap.get(nums[i])+1);
              } else {
                  valuesMap.put(nums[i], 1);
              }
          }
  </code></pre>
  
  <p>and still it prints 0 for <code>majorityRes</code>. Any idea why is that?</p>
  
  <p>UPDATE': Fixed the problem by changing to <code>containsKey()</code> which was a typo.</p>