diff options
| author | deadmarshal <adeadmarshal@gmail.com> | 2023-11-15 21:53:10 +0330 |
|---|---|---|
| committer | deadmarshal <adeadmarshal@gmail.com> | 2023-11-15 21:53:10 +0330 |
| commit | 7d92a145e089e59f0f830843ba91cd7223bc6c98 (patch) | |
| tree | 5e0043297d1fde64aa5c75c5e1440c4cbc393389 /challenge-243/deadmarshal/java/Ch1.java | |
| parent | d20e7296170b997b7e690a58b79156f6c81f1cd2 (diff) | |
| download | perlweeklychallenge-club-7d92a145e089e59f0f830843ba91cd7223bc6c98.tar.gz perlweeklychallenge-club-7d92a145e089e59f0f830843ba91cd7223bc6c98.tar.bz2 perlweeklychallenge-club-7d92a145e089e59f0f830843ba91cd7223bc6c98.zip | |
TWC243 extra solutions
Diffstat (limited to 'challenge-243/deadmarshal/java/Ch1.java')
| -rw-r--r-- | challenge-243/deadmarshal/java/Ch1.java | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-243/deadmarshal/java/Ch1.java b/challenge-243/deadmarshal/java/Ch1.java new file mode 100644 index 0000000000..ae2eb24e29 --- /dev/null +++ b/challenge-243/deadmarshal/java/Ch1.java @@ -0,0 +1,20 @@ +import java.util.ArrayList; +import java.util.List; + +public class Ch1 { + public static void main(String[] args) { + ArrayList<Integer> list1 = new ArrayList<>(List.of(1,3,2,3,1)); + ArrayList<Integer> list2 = new ArrayList<>(List.of(2,4,3,5,1)); + System.out.println(reverse_pairs(list1)); + System.out.println(reverse_pairs(list2)); + } + + private static int reverse_pairs(List<Integer> list) { + int count = 0; + for(int i = 0; i < list.size()-1; ++i) + for(int j = i+1; j < list.size(); ++j) + if(list.get(i) > 2 * list.get(j)) count++; + return count; + } +} + |
