实例: import java.util.*; //求学生最大成绩 public class Test{ public static void main(String[] args){ System.out.println("=======求学生最大成绩========="); Scanner in = new Scanner(System.in); int[] arr = new int[5]; //获取用户输入的每个学生的成绩 for(int i=0;i<arr.length
法一: import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { int[] a = new int[50]; Scanner scanner = new Scanner(System.in); int index = 0; String x; while(!(x=scanner.nextLine()).equals(""
[题目] Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. [思路] 注意sort,使得判断临接元素是否相邻. 与leetcode78类似,多了一个重复数判断条件 if(i>flag&&nums
//求出4×4矩阵中最大和最小元素值及其所在行下标和列下标,求出两条主对角线元素之和 #include <stdio.h> int main() { int sum=0; int max,min; int max1,max2;//记录最大值的坐标 int min1,min2;//记录最小值的坐标 int i,j; int a[4][4]; //为数组赋值 for(i=0;i<4;i++) { for(j=0;j<4;j++) { scanf("%d",&
题目原文: Decimal dominants. Given an array with n keys, design an algorithm to find all values that occur more than n/10 times. The expected running time of your algorithm should be linear. 分析: 直观上将n个元素遍历一遍,并记录每个元素出现的次数就可以实现,虽然时间复杂度是O(n),但是空间复杂度却高达n,这肯