given an array of integers Find the index of values that satisfy A+B = C + D
来源:互联网 发布:如何找淘宝主播合作 编辑:程序博客网 时间:2024/04/30 07:40
转自:http://www.careercup.com/question?id=5652354158297088
You're given an array of integers(eg [3,4,7,1,2,9,8]) Find the index of values that satisfy A+B = C + D, where A,B,C & D are integers values in the array.
Eg: Given [3,4,7,1,2,9,8] array
The following
3+7 = 1+ 9 satisfies A+B=C+D
so print (0,2,3,5)
struct Node{ int x; int y; Node(int a=0, int b=0):x(a),y(b){};};vector<int> Print4Sum(vector<int> A){ int tsum, l = A.size(); vector<int> ans; if (l < 4) return ans; map<int, Node> hashmap; for (int i = 0; i < l-1; ++i) for (int j = i+1; j < l; ++j) { tsum = A[i] + A[j]; if (hashmap.find(tsum) == hashmap.end()){ Node tnode = Node(i,j); hashmap[tsum] = tnode; }else{ Node tnode = hashmap[tsum]; int x = tnode.x, y = tnode.y; if (x != i && x != j && y != i && y != j) { ans.push_back(i); ans.push_back(j); ans.push_back(x); ans.push_back(y); sort(ans.begin(), ans.end()); return ans; } } } return ans;}
0 0
- given an array of integers Find the index of values that satisfy A+B = C + D
- CareerCup Given an array of (unsorted) integers, arrange them such that a < b > c < d > e... etc.
- Given an array of integers, return indices of the two numbers such that they add up to a specific ta
- Given an array of integers, every element appears twice except for one. Find that single one.
- Given an array of integers, every element appears twice except for one. Find that single one.
- Given an array of integers, every element appears twice except for one. Find that single one.
- Given an array of integers, every element appears twice except for one. Find that single one.
- Given an array of non-negative integers, you are initially positioned at the first index of the arra
- Given an array of size n, find the majority element. The majority element is the element that appear
- Given an array of integers, sort the array according to frequency of elements
- Given an array of ages (integers) sorted lowest to highest, output the number of occurrences for eac
- Given a non-empty array of integers, return the k most frequent elements.
- CareerCup Given an array having positive integers, find a subarray which adds to a given number
- 【LeetCode】169. Majority Element Majority Element Given an array of size n, find the majority eleme
- You’re given an array containing both positive and negative integers and required to find the sub-a
- Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
- 题目描述 Given n points on a 2D plane, find the maximum number of points that lie on the same straight
- Leetcode--->Given n points on a 2D plane, find the maximum number of points that lie on the same str
- Dom4j练习——三国杀武将管理系统
- iOS8
- 在redhat系统中安装g++(执行c++的程序)等软件时报错的解决方法
- apk编译/反编译工具baksmali和smali用法及apktool+dex2jar+jd_gui的用法
- DUMP工具介绍
- given an array of integers Find the index of values that satisfy A+B = C + D
- 2014-11-27 bec复习打卡
- java-抽象类和抽象函数
- linux下使用yum安装mysql详解
- 锻钠押桌畏俾琳琳干桌疽瞪矢蒙月
- 2014-11-28 bec复习打卡
- 既找前涝期帜辖辖谢牟街赐河笔呢
- 沼卣俾琳细舜铣迸匪城夹城谷澳食
- 环毡妒泄瞪畏窖粟铣匪挚米涝蛹刨