美文网首页
Arrays-算法练习

Arrays-算法练习

作者: fqyuan | 来源:发表于2017-08-13 16:00 被阅读0次

1. 问题描述

Find a triplet that sum to a given value

Given an array and a value, find if there is a triplet in array whose sum is equal to the given value. If there is such a triplet present in array, then print the triplet and return true.Else return false. For example, if the given array is {12, 3, 4, 1, 6, 9} and given sum is 24, then there is a triplet (12, 3 and 9) present in array whose sum is 24.

给定一个数组,判断是否有三个元素之和为给等的值,如存在返回true,否则返回false。

2. 解答

这里提供两种解答方案:

1). Brute force: O(n^3)

2). O(n^2), Sort the array first.

相关文章

  • Arrays-算法练习

    1. 问题描述 Find a triplet that sum to a given value Given an...

  • 前端干货 -03

    37. 算法 算法地址 数据结构与算法 JavaScript 描述. 章节练习https://github.com...

  • 算法-心得

    本周大部分的时间都在练习算法。虽说是有点被逼迫的意思,但是算法还是很重要的,也需要自己练习。 说到算法,我自身的感...

  • 算法练习(-)

    You are a professional robber planning to rob houses alon...

  • 算法练习

    将字符串转化为数字,实现int()方法 回文数 俩数之和 给定一个整数数组 nums 和一个目标值 target,...

  • 算法练习

    背景 Find closing/opening parenthesis You will be implement...

  • 算法练习

    2021 三月份 1. 两数之和 给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 ...

  • 刷算法 - 算法练习

    最近断断续续的刷了一些基础算法题. 我们做移动端开发的, 刷算法题有意义吗? 如果对这个问题有疑问, 可以在读这篇...

  • 2018-11-11 算法练习题

    下面是几道算法练习题:

  • iOS + 常用排序算法

    算练习吧参照的原文常用排序算法总结(一)八大排序算法

网友评论

      本文标题:Arrays-算法练习

      本文链接:https://www.haomeiwen.com/subject/jikerxtx.html