小编Sai*_*han的帖子

使用两个指针的算法的时间复杂度。是0(n)还是0(n^2)

所以这就是给出的问题。

给定一个整数数组,返回一个新数组,其中新数组中的每个元素都是原始输入数组中该元素右侧较小元素的数量。

例如,给定数组 [3, 4, 9, 6, 1],返回 [1, 1, 2, 1, 0],因为:

There is 1 smaller element to the right of 3
There is 1 smaller element to the right of 4
There are 2 smaller elements to the right of 9
There is 1 smaller element to the right of 6
There are no smaller elements to the right of 1
Run Code Online (Sandbox Code Playgroud)

我想出了这个两指针算法。

 function lessThan(arr) {
  let results = [];
  let i = 0;
  let j = arr.length - …
Run Code Online (Sandbox Code Playgroud)

javascript algorithm big-o time-complexity

5
推荐指数
1
解决办法
4848
查看次数

EJS 变量在 <script> 标签内工作,但 vscode 抛出错误

我在脚本标签中有一个 ejs 变量,它工作正常,但 vscode 抛出错误,说“需要表达式”这是代码

 <script type="text/javascript">
      var currentUser= <%- JSON.stringify(currentUser) %>
      console.log(currentUser);
    </script>
Run Code Online (Sandbox Code Playgroud)

我们可以看到 vscode 突出显示了错误

但它正在工作,我能够在浏览器控制台中看到 currentUser 对象 控制台截图

我无法弄清楚是什么导致了这个问题。有人可以帮我解决这个问题吗?

javascript ejs visual-studio-code

4
推荐指数
1
解决办法
1547
查看次数