Test cases needed to improve to detect my wrong code

  • 0
    class Solution {
        int maxProfit(vector<int> &prices) {
    		int sz=prices.size(), ret=0, leftMin=~(1<<31), tmpMax=0, rightMax=1<<31;
    		vector<int> leftMaxProfit(sz, 0);
    		for(int i=0;i<sz;++i)
    			leftMin=min(leftMin, prices[i]);			
    			leftMaxProfit[i]=max(leftMaxProfit[i], tmpMax=max(tmpMax, prices[i]-leftMin));
    		for(int i=sz-1;i>=0;--i)
    			rightMax=max(rightMax, prices[i]);
    			ret=max(ret, leftMaxProfit[i]+rightMax-prices[i]); //this line is big wrong, but it still passed all cases
    		return ret;

  • 0

    Thanks for reporting this. Could you please give at least one example test case which your code will get Wrong Answer?

Log in to reply

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