国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

[LintCode] Reverse Pairs

tigerZH / 877人閱讀

摘要:暴力解法就是時(shí)靈時(shí)不靈,兩次一次。希望看到的大神能夠分享優(yōu)質(zhì)的解法謝謝大家

Problem

For an array A, if i < j, and A[i] > A[j], called (A[i], A[j]) is a reverse pair.
return total of reverse pairs in A.

Example

Given A = [2, 4, 1, 3, 5] , (2, 1), (4, 1), (4, 3) are reverse pairs. return 3

Note

暴力解法就是時(shí)靈時(shí)不靈,submit兩次ac一次。
希望看到的大神能夠分享優(yōu)質(zhì)的解法^_^ linspiration1991@gmail.com

Solution
public class Solution {
    public long reversePairs(int[] A) {
        long res = 0;
        int n = A.length;
        for (int i = 0; i < n-1; i++) {
            for (int j = i; j < n; j++) {
                if (A[i] > A[j]) res += 1;
            }
        }
        return res;
    }
}
//謝謝大家!

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/65842.html

相關(guān)文章

  • [LeetCode/LintCode] Top K Frequent Words

    LeetCode version Problem Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, t...

    0x584a 評(píng)論0 收藏0
  • 兩數(shù)之和問(wèn)題各變種多解法小結(jié)

    摘要:兩數(shù)之和問(wèn)題各變種多解法小結(jié)聲明文章均為本人技術(shù)筆記,轉(zhuǎn)載請(qǐng)注明出處兩數(shù)之和等于題目大意給出未排序數(shù)組和指定目標(biāo),返回?cái)?shù)組中兩數(shù)之和的組合元素下標(biāo)要求下標(biāo)從開始,而且,保證題目中有且只有個(gè)可行解解法暴力時(shí)間復(fù)雜度求解解題思路暴力二重循環(huán)求解 兩數(shù)之和問(wèn)題各變種多解法小結(jié) 聲明 文章均為本人技術(shù)筆記,轉(zhuǎn)載請(qǐng)注明出處:[1] https://segmentfault.com/u/yzwal...

    lentoo 評(píng)論0 收藏0
  • [LintCode] K-diff Pairs in an Array

    Problem Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both nu...

    Leck1e 評(píng)論0 收藏0
  • [LeetCode/LintCode] Sentence Similarity

    Problem Given two sentences words1, words2 (each represented as an array of strings), and a list of similar word pairs pairs, determine if two sentences are similar. For example, great acting skills a...

    dreamtecher 評(píng)論0 收藏0
  • [LintCode] Swap Nodes in Pairs

    摘要:指針為,我們選擇的兩個(gè)結(jié)點(diǎn)是和。要注意循環(huán)的邊界條件,這兩個(gè)結(jié)點(diǎn)不能為空。主要思路是先用和兩個(gè)新結(jié)點(diǎn)去保存和兩個(gè)結(jié)點(diǎn)。完成交換之后,連接和,并讓前進(jìn)至此時(shí)的結(jié)點(diǎn)。 Problem Given a linked list, swap every two adjacent nodes and return its head. Example Given 1->2->3->4, you sh...

    EscapedDog 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<