Find a pair of elements from an array whose sum equals a given number

后端 未结 30 1366
暗喜
暗喜 2020-11-22 10:14

Given array of n integers and given a number X, find all the unique pairs of elements (a,b), whose summation is equal to X.

The following is my solution, it is O(nLo

30条回答
  •  一生所求
    2020-11-22 10:55

    Just attended this question on HackerRank and here's my 'Objective C' Solution:

    -(NSNumber*)sum:(NSArray*) a andK:(NSNumber*)k {
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        long long count = 0;
        for(long i=0;i

    Hope it helps someone.

提交回复
热议问题