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

主要看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. OSX安装nginx和rtmp模块(rtmp直播服务器搭建)

    1.安装Homebrew,执行命令 1 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/ma ...

  2. iOS 从网络获取son并解析

    NSString* GXURL = PURL; GXURL = [GXURL stringByAppendingString:@"/index.php/Api/android_getRank ...

  3. JavaScript Boolean(布尔) 对象

    创建 Boolean 对象 Boolean 对象代表两个值:"true" 或者 "false" 下面的代码定义了一个名为 myBoolean 的布尔对象: va ...

  4. javascript——面向对象程序设计(1)

    <script type="text/javascript"> //ECMA-262把对象定义为:“无序属性的 集合,其属性可以包含基本值.对象或者函数” //理解对象 ...

  5. linux 日常命令(磁盘空间)

    df –hl 在windows下可以很方便的查看磁盘空间的.但是到了Linux查看磁盘空间,你可能就有点摸不着头脑了,呵呵.不要急,我这就要给你解决这个问题. Df命令是Linux查看磁盘空间系统以磁 ...

  6. .net程序员必须知道的知识

    A while back, I posted a list of ASP.NET Interview Questions. Conventional wisdom was split, with ab ...

  7. PHP面向对象(OOP):__call()处理调用错误

    在程序开发中,如果在使用对象调用对象内部方法时候,调用的这个方法不存在那么程序就会出错,然后程序退出不能继续执行.那么可不可以在程序调用对象内部 不存在的方法时,提示我们调用的方法及使用的参数不存在, ...

  8. thinkphp微信开发之jssdk图片上传并下载到本地服务器

    public function test2(){ $Weixin = new \Weixin\Controller\BaseController(); $this->assign('signPa ...

  9. 如何让同一个字段在不同的view中显示不同的内容

    many2one 字段默认显示 对象的name字段, 但也可以定义name_get方法显示不同的内容 如res.partner 对象可以根据 context 内容是否显示 客户的地址,职位,email ...

  10. .net序列化和反系列化json与类型对象转换

    先添加程序集:  System.Web.Extensions(在 System.Web.Extensions.dll 中) 引用:using System.Web.Script.Serializati ...