GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — algorithm/java/src/main/java/BreakingTheRecords.java at master · funfunStudy/algorithm Expand file tree/ Copy pathBreakingTheRecords.javaMore file actions 95 lines (72 loc) · 2.27 KB / Copy pathBreakingTheRecords.javaFile metadata and controls95 lines (72 loc) · 2.27 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 import java.util.Arrays; import java.util.Scanner; public class BreakingTheRecords { public static void main(String[] args) { Scanner sc = new Scanner(System.in); BreakingTheRecords btr = new BreakingTheRecords(); int count = sc.nextInt(); int[] arr = new int[count]; for (int i = 0; i < count; i++) arr[i] = sc.nextInt(); // System.out.println(btr.btrMaxRec(arr[0], arr, 0, 0)); // // System.out.println(btr.btrMinRec(arr[0], arr, 0, 0)); System.out.println(Arrays.toString(btr.btrMaxMin(arr, arr[0], arr[0], 0, new int[2]))); } //3 private int[] btrMaxMin(final int[] arr, final int max, final int min, final int index, final int[] count) { if (index >= arr.length) return count; int tempMax = max; int tempMin = min; int tempIndex = index; int[] tempCount = count.clone(); if (arr[index] > max) { tempMax = arr[index]; tempCount[0] = count[0] + 1; } if (arr[index] < min) { tempMin = arr[index]; tempCount[1] = count[1] + 1; } return btrMaxMin(arr, tempMax, tempMin, ++tempIndex, tempCount); } //2 private int btrMaxRec(int max, int[] arr, int count, int index) { if (index >= arr.length) return count; if (arr[index] > max) { return btrMaxRec(arr[index], arr, ++count, ++index); } else { return btrMaxRec(max, arr, count, ++index); } } private int btrMinRec(int min, int[] arr, int count, int index) { if (index >= arr.length) return count; if (arr[index] < min) { return btrMinRec(arr[index], arr, ++count, ++index); } else { return btrMinRec(min, arr, count, ++index); } } //1 private int btrMax(int max, int[] arr, int count) { for (int i : arr) { if (i > max) { max = i; count++; } } return count; } private int btrMin(int min, int[] arr, int count) { for (int i : arr) { if (i < min) { min = i; count++; } } return count; } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |