解决方案无法通过一次大输入测试?

时间:2017-09-10 14:40:23

标签: javascript

<table>
  <tr>
    <td style="position: relative; width: 100px">
      <div style="position: absolute; left: 0px; width: 220px;">valid from</div>
      <div style="position: absolute; left: 280px; width: 120px;">valid from</div>
    </td>
    <td style="width: 100px"></td>
    <td style="width: 100px"></td>
  </tr>
</tr>

问题出在这里 - https://www.hackerrank.com/challenges/birthday-cake-candles/problem

1 个答案:

答案 0 :(得分:0)

无需对数组进行排序,您可以在 O(n) 次中解决问题

function birthdayCakeCandles(arr, n) {
    var total = 0;
    var len = arr.length;
    for (var i = 0; i < len; i++) {
        if (ar[i] === n) 
            total++;
    }
    return total;