Advertisement
stepan12123123123

Untitled

Feb 19th, 2023
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.53 KB | None | 0 0
  1. class Solution {
  2.     fun twoSum(nums: IntArray, target: Int): IntArray {
  3.         val hash = HashMap<Int, Int>();
  4.         var ind1: Int = 0;
  5.         var ind2: Int = 0;
  6.         for(i in 0 until nums.size) {
  7.             hash[nums[i]] = i;
  8.         }
  9.         for(i in 0 until nums.size) {
  10.             var t: Int = target - nums[i];
  11.             if(t in hash && i != hash[t]){
  12.                 ind1 = i;
  13.                 ind2 = hash[t]!!;
  14.                 break
  15.             }
  16.         }
  17.         return intArrayOf(ind1, ind2)
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement