領扣LintCode問題答案 58 四數之和

2021-10-08 23:47:45 字數 814 閱讀 8026

領扣lintcode問題答案-58. 四數之和

給乙個包含n個數的整數陣列s,在s中找到所有使得和為給定整數target的四元組(a, b, c, d)。

四元組(a, b, c, d)中,需要滿足a <= b <= c <= d

答案中不可以包含重複的四元組。

樣例 1:

輸入:[2,7,11,15],3

輸出:

樣例 2:

輸入:[1,0,-1,0,-2,2],0

輸出:[[-1, 0, 0, 1]

,[-2, -1, 1, 2]

,[-2, 0, 0, 2]]

public

class

solution

if(sum == target)

}while

(k +

1< numbers.length

&& numbers[k]

== numbers[k +1]

)}while

(j +

1< numbers.length

&& numbers[j]

== numbers[j +1]

)}while

(i +

1< numbers.length

&& numbers[i]

== numbers[i +1]

)}return ret;

}}

原題鏈結點這裡

領扣LintCode演算法問題答案 920 會議室

領扣lintcode演算法問題答案 920.會議室 給定一系列的會議時間間隔,包括起始和結束時間 s1,e1 s2,e2 si ei 確定乙個人是否可以參加所有會議。0,8 8,10 在8這這一時刻不衝突 樣例 1 輸入 intervals 0,30 5,10 15,20 輸出 false 解釋 0...

領扣LintCode問題答案 57 三數之和

領扣lintcode問題答案 57.三數之和 給出乙個有n個整數的陣列s,在s中找到三個整數a,b,c,找到所有使得a b c 0的三元組。在三元組 a,b,c 要求a b c。結果不能包含重複的三元組。樣例 1 輸入 2,7,11,15 輸出 樣例 2 輸入 1,0,1,2,1,4 輸出 1,0,...

領扣LintCode演算法問題答案 98 鍊錶排序

領扣lintcode演算法問題答案 98.鍊錶排序 題解鳴謝 在 o n log n 時間複雜度和常數級的空間複雜度下給鍊錶排序。輸入 1 3 2 null 輸出 1 2 3 null輸入 1 7 2 6 null 輸出 1 2 6 7 null definition for listnode pu...