思路分析:尼玛这不就是等差数列么.首先将该n-1个整数相加,得到sum,然后用(1+n)n/2减去sum,得到的差即为缺失的整数.因为1~n一共n个数,n个数的和为(1+n)n/2,而未排序数列的和为sum,二者之差即为确实的数. 程序示例如下: #include "stdafx.h" #include <stdio.h> #define MAX 5 int main() { int array[MAX] = { 3, 2, 1, 6, 4 }; int i; int su
题目 给一组整数,按照升序排序.使用归并排序,快速排序,堆排序或者任何其他 O(n log n) 的排序算法. 解题 归并排序 public class Solution { /** * @param A an integer array * @return void */ public void sortIntegers2(int[] A) { // Write your code here if(A==null || A.length <=1) return; int low = 0; in
Description Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let’s say the phone catalogue listed these numbers: 1. Emergency 911 2. Alice 97 625 999 3. Bob 91 12 54 26 In this case, i
6/12 2016 Multi-University Training Contest 4官方题解 KMP+DP A Another Meaning(CYD) 题意: 给一段字符,同时给定你一个单词,这个单词有双重意思,字符串中可能会有很多这种单词,求这句话的意思总数:hehe. 思路: 可以用kmp算法快速求出串中的单词数量,若单词是分开的,每个单词有两种意思,可以直接相乘,若两个及以上单词在原串中是有交集的,那么数量不是直接相乘,发现这片连在一起的单词数量dp[i]=dp[i-1]+dp[j