所以这就是给出的问题。
给定一个整数数组,返回一个新数组,其中新数组中的每个元素都是原始输入数组中该元素右侧较小元素的数量。
例如,给定数组 [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) 我在脚本标签中有一个 ejs 变量,它工作正常,但 vscode 抛出错误,说“需要表达式”这是代码
<script type="text/javascript">
var currentUser= <%- JSON.stringify(currentUser) %>
console.log(currentUser);
</script>
Run Code Online (Sandbox Code Playgroud)
但它正在工作,我能够在浏览器控制台中看到 currentUser 对象

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