Sort Transformed Array
2016-06-27 12:49
387 查看
public class Solution { public int[] sortTransformedArray(int[] nums, int a, int b, int c) { if (nums.length < 2) { return nums; } int[] result = new int[nums.length]; int start = 0, end = nums.length - 1; int index = a > 0 ? nums.length - 1 : 0; while (start <= end) { if (a > 0) { result[index--] = getF(nums[start], a, b, c) > getF(nums[end], a, b, c) ? getF(nums[start++], a, b, c) : getF(nums[end--], a, b, c); } else { result[index++] = getF(nums[start], a, b, c) < getF(nums[end], a, b, c) ? getF(nums[start++], a, b, c) : getF(nums[end--], a, b, c); } } return result; } private int getF(int x, int a, int b, int c) { return a * x * x + b * x + c; } }
1. This is a parabola function. So two ends always larger than mid.
2. remember return value.
相关文章推荐
- vxworks的启动任务taskSpawn
- 添物零基础到大型全栈架构师 不花钱学计算机及编程(预备篇)- 计算机基础
- 添物零基础到大型全栈架构师 不花钱学计算机及编程(预备篇)- 计算机基础
- Android网络请求框架剖析一、Okhttp
- Android EventBus实战及源码解析 (一)
- mac中Eclipse的快捷键
- 【NOIP2013模拟联考5】军训(training)
- win7系统怎么判断是否需要手动安装KB3161647补丁?
- osg 骨骼绘制 注意事项
- Linux系统传输文件小工具lrzsz
- 理解Gradle
- 牛顿迭代法
- 【初探Spring】——Spring IOC(三):初始化过程—Resource定位
- 小马哥--高仿苹果6sp 9900-999AQ0A另款9900机型 6582芯片刷机拆机主板多图展示
- 作业九 课程总结(附加补充)
- RabbitMQ java API中文翻译
- swift 重写set方法
- 推荐一个开源库(Calligraphy)将ttf字体库加入到项目中,轻松实现各种字体
- vmware fusion下win7分辨率自动切换解决办法
- MySQL分页性能优化