Daily Coding Problem: Problem #339
Posted johnnyzhao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Daily Coding Problem: Problem #339相关的知识,希望对你有一定的参考价值。
/** * This problem was asked by Microsoft. Given an array of numbers and a number k, determine if there are three entries in the array which add up to the specified number k. For example, given [20, 303, 3, 4, 25] and k = 49, return true as 20 + 4 + 25 = 49. * */ class Problem_339 fun sumUpEqualK(array: IntArray, K: Int): Boolean var left = 0 val size = array.size var right = 0 array.sort() for (i in 0 until size) left = i + 1 right = size - 1 while (left < right) val value = array[i] + array[left] + array[right] if (value < K) left++ else if (value > K) right-- else return true return false
以上是关于Daily Coding Problem: Problem #339的主要内容,如果未能解决你的问题,请参考以下文章
[Daily Coding Problem 290] Quxes Transformation
[Daily Coding Problem 250] Cryptarithmetic Puzzle
[Daily Coding Problem 70] Nth perfect number
[Daily Coding Problem 68] Count Pairs of attacking bishop pairs
[Daily Coding Problem 24] Implement locking in a binary tree.
[Daily Coding Problem 294] Shortest round route with rising then falling elevations