title: putting value in Treemap understanding issues
body: <p>I was running through a leetcode problem. and found a solution in the discussion section</p>
  <p>problem- <a href="https://leetcode.com/problems/stock-price-fluctuation/" rel="nofollow noreferrer">https://leetcode.com/problems/stock-price-fluctuation/</a></p>
  <p>solution-</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>class StockPrice {
      HashMap&lt;Integer, Integer&gt; hm; //timestamp,price
      TreeMap&lt;Integer, Integer&gt; tm; //price, frequency
      int current;
      
      public StockPrice() {
          
          hm = new HashMap&lt;&gt;();
          tm = new TreeMap&lt;&gt;();
          current = 0;
  
      }
      
      public void update(int timestamp, int price) {
          
          //check whether latest timestamp or current timestamp is larger...
          current = Math.max(current, timestamp); //if timesatamp already present
          if(hm.containsKey(timestamp))
          {
              
              int oldprice=hm.get(timestamp);
  
             if(tm.get(oldprice)==1){
                 tm.remove(oldprice); // 
             }
              else{
                  tm.put(oldprice, tm.get(oldprice)-1); 
                  
              }
          }
          //update new price in hm
          hm.put(timestamp, price);
          //update new frequency of new price in treemap
          tm.put (price, tm.getOrDefault(price,0)+1);
          
      }
      
      public int current() {
      return hm.get(current);
      }
      
      public int maximum() {
          return tm.lastKey();
      }
      
      public int minimum() {
          return tm.firstKey();
          
      }
  }</code></pre>
  </div>
  </div>
  
  but I do not understand the following parts.
  if someone could explain that would be great</p>
  <ol>
  <li>
  <pre><code>                tm.put(oldprice, tm.get(oldprice)-1); 
  </code></pre>
  </li>
  <li>
  <pre><code>        tm.put (price, tm.getOrDefault(price,0)+1);
  </code></pre>
  </li>
  </ol>