前些天看到.net笔试习题集上的一道小题,要求将1至100内的正整数随机填充到一个长度为100的数组,求一个简单的算法. 今天有空写了一下.代码如下,注释比较详细: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace TestNumber { class Program { //定义
主要思想: 数组可以无序 假设数字里的值都为正 循环判断数组 如果与前面的数字相同则变为-1 然后记录-1的个数算出重复值 然后重新new一个减去重复值长度的新数组 和原数组判断 不为-1的全部复制进来即可 代码如下: package Del_Same_Num; public class Del_Same_Num { static int count=0; //计算重复值 public static int count_same_number(int[] a) { for(int i=0;i<a
<!doctype html public "-//W3C//DTD HTML 4.0 //EN"> <html><head> <title>PHP的数组值传入JavaScript的数组里</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><s
// 数组里相邻两个数做比较 取满足条件的那个(以此类推) var arr = [1,3,4,5,6,7]; function Max(array){ var max = array[0]; for(var i=0; i<array.length; i++){ if(max<array[i]) max = array[i]; } return max; } console.log(Max(arr)); function Min(array){ var min = array[0]; for(v
This is a follow up problem to Search in Rotated Sorted Array, where nums may contain duplicates. 思路 该题是[leetcode]33. Search in Rotated Sorted Array旋转过有序数组里找目标值 的followup 唯一区别是加了line24-26的else语句来skip duplicates 代码 class Solution { public boolean sear