File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121var rob = function ( nums ) {
2222 var currMaxPV = 0 , //当前最大值:上一轮循环中的最大值加上当前值
2323 lastRealMax = 0 , //上一轮循环中的真正的最大值
24- i = nums . length - 1 ,
25- tempLastMaxPV , //
26- realLastMax ;
24+ i = nums . length - 1 ;
25+
2726 while ( 0 <= i ) { // eg: [2,1,1,2]
28- tempLastMaxPV = currMaxPV ; //2 0 3
29- realLastMax = lastRealMax ; //0 2 2
30- currMaxPV = realLastMax + nums [ i ] ; //1 3 4
31- lastRealMax = tempLastMaxPV > realLastMax ? tempLastMaxPV : realLastMax ; //2 2 3
32- i -- ;
27+ var tempLastMaxPV = currMaxPV , //2 0 3
28+ realLastMax = lastRealMax ; //0 2 2
29+ currMaxPV = realLastMax + nums [ i ] ; //1 3 4
30+ lastRealMax = Math . max ( tempLastMaxPV , realLastMax ) ; //2 2 3
31+ i -- ;
3332 }
34- return currMaxPV > lastRealMax ? currMaxPV : lastRealMax ;
33+ return Math . max ( currMaxPV , lastRealMax ) ; // 4
3534} ;
35+
You can’t perform that action at this time.
0 commit comments