马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
在写力扣题目时,报
<--- Last few GCs --->
[42:0x6602180] 359 ms: Mark-sweep (reduce) 133.2 (138.1) -> 82.7 (84.7) MB, 13.9 / 0.0 ms (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 14 ms) (average mu = 0.770, current mu = 0.775) last resort G[42:0x6602180] 372 ms: Mark-sweep (reduce) 82.7 (84.7) -> 82.7 (84.4) MB, 12.7 / 0.0 ms (average mu = 0.624, current mu = 0.001) last resort GC in old space requested
<--- JS stacktrace --->
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: 0xb00e10 node::Abort() [nodejs run]
2: 0xa1823b node::FatalError(char const*, char const*) [nodejs run]
3: 0xcee09e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [nodejs run]
4: 0xcee417 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [nodejs run]
5: 0xea65d5 [nodejs run]
6: 0xeb8a58 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [nodejs run]
7: 0xe79b12 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [nodejs run]
8: 0xe7443c v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawArray(int, v8::internal::AllocationType) [nodejs run]
9: 0xe74515 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller(v8::internal::Handle<v8::internal::Map>, int, v8::internal::Handle<v8::internal::Oddball>, v8::internal::AllocationType) [nodejs run]
10: 0x10221b2 [nodejs run]
11: 0x1022af6 [nodejs run]
12: 0x11e3783 v8::internal::Runtime_GrowArrayElements(int, unsigned long*, v8::internal::Isolate*) [nodejs run]
13: 0x15e7cf9 [nodejs run]
错误
题为力扣 121. 买卖股票的最佳时机
我的代码为:/**
* @param {number[]} prices
* @return {number}
*/
var maxProfit = function(prices) {
let result=[]
if(prices.length<=1){
return 0
}
for(let i=0;i<prices.length;i++){
for(let j=i+1;j<prices.length;j++){
if((prices[j]-prices[i])<0){
result.push(0)
}
else{
result.push(prices[j]-prices[i])
}
}
}
result.sort(function(a, b){return a-b})
return result[result.length-1]
};
不知道哪里错了 |