一元二次方程。。。仿佛回到了初中。

主要看a的情况来分情况讨论:

=0,一次函数,根据b的正负单调递增递减就行了。

<0,凸状。。从nums[]左右两边开始往中间一边比较一边 从右往左 放;

0,凹状。。从左往右。。

public class Solution {
public int[] sortTransformedArray(int[] nums, int a, int b, int c)
{
int n = nums.length;
int[] res = new int[n];
int i = 0;
if(a == 0)
{ if(b >= 0) while(i < n) res[i] = nums[i++]*b + c;
else
while(i < n)
{
res[i] = nums[n-1-i]*b + c;
i++;
}
}
else
{
int l = 0;
int r = n-1;
int M = -b/a; while(i < n)
{
int p = cal(nums[l],a,b,c);
int q = cal(nums[r],a,b,c); if(a > 0)
{
if(p > q)
{
l++;
res[n-1-i] = p;
}
else
{
r--;
res[n-1-i] = q;
}
}
else
{
if(p < q)
{
l++;
res[i] = p;
}
else
{
r--;
res[i] = q;
}
}
i++;
}
}
return res; } public int cal(int x, int a, int b, int c)
{
return a*x*x + b*x + c;
}
}

360. Sort Transformed Array的更多相关文章

  1. 360. Sort Transformed Array二元一次方程返回大数序列

    [抄题]: Given a sorted array of integers nums and integer values a, b and c. Apply a quadratic functio ...

  2. LeetCode 360. Sort Transformed Array

    原题链接在这里:https://leetcode.com/problems/sort-transformed-array/description/ 题目: Given a sorted array o ...

  3. [LeetCode] 360. Sort Transformed Array 排序转换后的数组

    Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f( ...

  4. Leetcode: Sort Transformed Array

    Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f( ...

  5. [LeetCode] Sort Transformed Array 变换数组排序

    Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f( ...

  6. Sort Transformed Array

    Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f( ...

  7. Sort Transformed Array -- LeetCode

    Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f( ...

  8. CF451B Sort the Array 水题

    Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...

  9. [CareerCup] 11.2 Sort Anagrams Array 异位词数组排序

    11.2 Write a method to sort an array of strings so that all the anagrams are next to each other. 这道题 ...

随机推荐

  1. iOS9适配中出现的一些常见问题

    本文主要是说一些iOS9适配中出现的坑,如果只是要单纯的了解iOS9新特性可以看瞄神的开发者所需要知道的 iOS 9 SDK 新特性.9月17日凌晨,苹果给用户推送了iOS9正式版,随着有用户陆续升级 ...

  2. jQuery Callback 方法

    Callback 函数在当前动画 100% 完成之后执行. jQuery 动画的问题 许多 jQuery 函数涉及动画.这些函数也许会将 speed 或 duration 作为可选参数. 例子:$(& ...

  3. 平衡搜索树(一) AVL树

    AVL树 AVL树又称为高度平衡的二叉搜索树,是1962年有俄罗斯的数学家G.M.Adel'son-Vel'skii和E.M.Landis提出来的.它能保持二叉树的高度 平衡,尽量降低二叉树的高度,减 ...

  4. Xcode编译项目出现访问private key提示框

    原因: 在编译时Xcode进行codesign时需要访问"private key"时没有权限,然后让询问是否允许,有三个选项,全部允许.否绝.允许,一次弹出4个(我遇到的) 遇到问 ...

  5. 在CentOS 7中轻松安装Atomic应用(atomicapp)

    sudo yum install docker atomic etcd kubernetes sudo systemctl enable docker.service sudo systemctl s ...

  6. 装了SVN,你的关联图标变了没有?

    装了SVN,你的关联图标变了没有? 开始合作之后,装上了SVN,非常高效,我在VS写了一部分的代码,上传之后,别人通过下载或是更新,就更新到了合作同伴的VS里,相当于大家在一个VS里写代码.和保强他们 ...

  7. 用jQuery实现瀑布流效果学习笔记

    jQuery一直没系统的学,只知道是js库,封装了好多js函数,方便了开发.以前做过一个原生的图片网站瀑布流效果,超级麻烦,这次用了jQuery方法,瞬间代码浓缩了,只有56行js代码.神奇的让我来把 ...

  8. 快速替换图片的组合-AE-样片!

    模板下载网址:http://pan.baidu.com/s/1hqCbErM

  9. Unity的Profiler性能分析

    1. CPU Usage A. WaitForTargetFPS: Vsync(垂直同步)功能所,即显示当前帧的CPU等待时间 B. Overhead: Profiler总体时间-所有单项的记录时间总 ...

  10. libevent带负载均衡的多线程使用示例

    功能: 主线程根据负载工作线程负载均衡算法,每隔一秒钟向特定的工作线程发送一条字符串信息,工作线程简单的把字符串信息打开出来.   Makefile   eventtest : eventtest.c ...