java - 数组IntList(java)

标签 java

Write a method isPairwiseSorted that returns whether or not a list of integers is pairwise sorted (true if it is, false otherwise). A list is considered pairwise sorted if each successive pair of numbers is in sorted (non-decreasing) order.

我编写了以下方法,但它总是返回 true。请在这里需要一些帮助。

public boolean isPairwiseSorted() {
    boolean isFalse=false;
    for(int i = 0; i < size; i+=2){
        if( elementData[i] < elementData[i+1] || size == 0 || size == 1){
            return true;
        }
    }
    return isFalse;
}

最佳答案

if (size == 0 || size == 1)
   return true;

for (int i = 0; i < size - 1; i += 2)
{
   if (elementData[i] > elementData[i+1])
      return false;
}

return true;

关于java - 数组IntList(java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15047537/

相关文章:

java - 仅用于两个逗号分隔值的正则表达式,使第二个值保持可选

java - 不能使用 jni 从 eclipse 生成的 dll

java - 无需浏览器即可打开并监视运行 Flash 应用程序的窗口

java - 深入探讨 Hazelcast 新手的问题

java - 读取文件中的 double

java - Activity 对象@Implementation注解递归

java - MalformedStreamException : Stream ended unexpectedly

java - Java中jsp显示List的问题

java - 从另一个 jar 文件访问资源

java - 使用 JAXB 从 webservice 解析 xml 的一些问题