LeeCode example | LeeCode example

owenjorney 1 0 zip 2024-10-04 22:10:09

leetcode推前LeeCode_example参考1. 二和给定一个整数数组,返回两个数字的索引,使它们相加为特定目标。您可以假设每个输入都只有一个解决方案,并且您不能两次使用相同的元素。示例:给定nums = [2, 7, 11, 15], target = 9,因为nums[0] + nums[1] = 2 + 7 = 9,返回[0, 1]。 O(n^2): class Solution { public: vector< int > twoSum (vector< int >& nums, int target) { vector< int > output; for ( int i= 0 ; i

用户评论
请输入评论内容
评分:
暂无评论