Distance Between Bus Stops Solution in C++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int distanceBetweenBusStops(vector<int>& distance, int start, int destination) {\n        int i, dis1=0, dis2=0, j, temp;\n\n        // Swapping the values of start and destination, if destination is smaller than start\n        if(start>destination)\n        {\n            temp = start;\n            start = destination;\n            destination = temp;\n        }\n\n        //Checking Forward distance\n        for(i=start ; i<destination ; i++)\n        {\n            dis1 += distance[i];\n        }\n\n        //Checking Backward distance\n        i = start-1;\n        j = distance.size()-destination+start;\n        while(j>0)\n        {\n            if(i<0)\n            {\n                dis2 += distance[distance.size()+i];\n            }\n            else\n                dis2 += distance[i];\n            i--;\n            j--;\n        }\n\n        // Result\n        if(dis1<dis2)\n            return dis1;\n        return dis2;\n    }\n};\n```\n![upvote new.jpg](https://assets.leetcode.com/users/images/07016b53-8ada-4070-aab3-3dbdab28415c_1682917170.9058347.jpeg)\n
['C++']