A 0 ms C sloution


  • 0
    int rob(int* n, int ns)
    {
    	int pre,cur, t;
    	int i, j, max = 0;
    	for (j = 0; j < 3; ++j)
    	{
    		pre = cur = n[j];
    		for (i = j + 2; i < (ns - (!j)); ++i)
    		{
    			t = cur>(pre + n[i]) ? cur : (pre + n[i]);
    			pre = cur;
    			cur = t;
    		}
    		max = max>cur ? max : cur;
    	}
    	return max;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.