title: Lowercase 'g' in a string is "happy" if there is another 'g' immediately next to it
body: <p>I need to implement code where lowercase <code>'g'</code> in a string is "happy" if there is another <code>'g'</code> adjacent to it. Then, return <code>true</code> if all the <code>g's</code> in the given string are happy. For example:</p>
  
  <blockquote>
    <p>gHappy("xxggxx") → true<br>
    gHappy("xxgxx") → false<br>
    gHappy("xxggyygxx") → false </p>
  </blockquote>
  
  <p>Here is the code I tried:</p>
  
  <pre><code>public boolean gHappy(String str) {
    if(str.length() &lt; 1){
       return false;
    }
  
    boolean result = false;
    for(int i = 1; i &lt; str.length() - 1; i++){
       if(str.charAt(i) == 'g' &amp;&amp; str.charAt(i - 1) == 'g' 
       || str.charAt(i + 1) == 'g'){
          result = true;
  
       }
    }
  
    return result;
  }
  </code></pre>
  
  <p>But Im failing some of the test cases such as:</p>
  
  <blockquote>
    <p>gHappy("gg") → should be <code>true</code> → getting <code>false</code><br>
    gHappy("xxgggxyg") → should be <code>false</code> → getting <code>true</code></p>
  </blockquote>