Why my runtime beats 89.81% of cpp submissions? Jesus!


  • -29
    F

    this is my Inefficient and insignificant code:

    class Solution { public: vector twoSum(vector& nums, int target) { vectoranswer; vectornum=nums; sort(num.begin(),num.end()); int lhs=0,result; int rhs=nums.size()-1; while(1) { result=num.at(lhs)+num.at(rhs); if(result>target) { rhs--; } else if(result==target) { break; } else { lhs++; } } int index1=-1,index2=-1; for(int i=0,size=nums.size();i<size;i++) { if((nums.at(i)==num.at(lhs))&&(index1==-1)) { index1=i; } if(nums.at(i)==num.at(rhs)) { index2=i; } } if(index1<index2) { answer.pushback(index1+1); answer.pushback(index2+1); } else { answer.pushback(index2+1); answer.pushback(index1+1); } return answer; } };
    

    but i beats 90% of the guys! unbelievable!


  • 0
    Z

    can you compose type your code?


Log in to reply
 

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