制作静态网站需要什么,企业建设网站的一般过程,牡丹江出现一例,可视化数据平台1 题目
给定一个整数数组 nums 和一个目标值 target#xff0c;请你在该数组中找出和为目标值的那 两个 整数#xff0c;并返回他们的数组下标。
你可以假设每种输入只会对应一个答案。但是#xff0c;数组中同一个元素不能使用两遍。
2 解法
struct haveOrigionIndexNu…1 题目
给定一个整数数组 nums 和一个目标值 target请你在该数组中找出和为目标值的那 两个 整数并返回他们的数组下标。
你可以假设每种输入只会对应一个答案。但是数组中同一个元素不能使用两遍。
2 解法
struct haveOrigionIndexNumber {int origionIndex;int value;
};
bool valueUp(haveOrigionIndexNumber first, haveOrigionIndexNumber second) {return first.value second.value;
}
class Solution {
public:vectorint twoSum(vectorint nums, int target) {vectorint res_index_vec;vectorhaveOrigionIndexNumber tVec;for (int i 0; i nums.size(); i ) {haveOrigionIndexNumber tNumber;tNumber.origionIndex i;tNumber.value nums[i];tVec.push_back(tNumber);}sort(tVec.begin(), tVec.end(), valueUp);int left 0;int right tVec.size() - 1;while (left right) {if (tVec[left].value tVec[right].value target) {left ;} else if (tVec[left].value tVec[right].value target) {right --;} else {res_index_vec.push_back(tVec[left].origionIndex);res_index_vec.push_back(tVec[right].origionIndex);return res_index_vec;}}return res_index_vec;}
};
性能不咋地: