LeetCode - Two Sum
Summary:
1. vector<int> ret(2, 0);
apply a vector: (size, initial value).
2. index starts from one (not zero).
3. small index comes first, big index comes next.
4. attention to the special condition: input one element in vector.
5. <Algorithm> library:
sort(nums.begin(), nums.end(), compare);
bool compare(const& T1, const& T2){return ...}
min, max;
6. data structure: map<int, int>. (all 0 in default)
*use multiply as key, then judge the sum.
*attention to multiply-numbers, use "long long" type.
7. Java data structure:
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
map.containsKey(num);
map.put(num, index);
index = map.get(num);
posted on 2013-04-13 21:13 highstar88 阅读(127) 评论(0) 编辑 收藏 举报