07 2016 档案
摘要:题目: Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For
阅读全文
摘要:1.排序算法 . 计算机科学发展至今,已经出现了许多种不同的排序算法。在本章的课程中,介绍了插入排序(insertion sort)、冒泡排序(bubble sort)、归并排序(merge sort)、选择排序(selection sort) 和 快速排序(quick sort)这 5 种排序算法
阅读全文
摘要:1.查找(search) 是指在数据集合中寻找满足某种条件的数据元素的过程。用于查找的数据集合则称为 查找表(search table)。查找表中的数据元素类型是一致的,并且有能够唯一标识出元素的 关键字(keyword)。如果从查找表中找出了关键字等于某个给定值的数据元素,则称为 查找成功,否则称
阅读全文
摘要:题目: 建立一颗二叉查找树,输出每个节点的数值以及该节点的左右子树的数值。 格式如下: 输入格式: 第一行输入一个正整数 N (1 <= N <= 1000),代表序列里元素个数。 第二行输入 N 个正整数,代表序列 a 的 N 个元素(0 <= ai <= 10000)。保证序列里的元素值互不相同
阅读全文
摘要:1.二叉查找树又称为二叉搜索树。二叉查找树和普通的二叉树在结构上一样,它要么是一棵空树,要么是这样的一棵二叉树:对任意结点,如果左子树不为空,则左子树上所有结点的权值都小于该结点的权值;如果右子树不为空,则右子树上所有结点的权值都大于该结点的权值;任意结点的左子树和右子树都是一棵二叉查找树;一般而言
阅读全文
摘要:1.树形结构广泛存在我们的现实生活里,如下两张图,第一张是 Linux 文件系统结构,第二张是美国福特汽车公司的汽车家谱图。类似的树形结构还有很多,他们都可以抽象成数据结构里的树。和自然界里的树有所类似又有所不同,他们都有且仅有一个树根,树上的元素都是从树根衍生出来的。不同的是自然界里的树,它的树根
阅读全文
摘要:1.我们在网站上注册账号时,当填好用户名后,系统都会判断用户名是否已被使用,如果已被使用,系统就会提示该用户名已被注册。系统是如何检测用户名是否被使用的? 可以用哈希表来解决这个问题。哈希表又叫散列表,关键值通过哈希函数映射到数组上,查找时通过关键值直接访问数组。在上面的例子里,我们将用户名通过哈希
阅读全文
摘要:1.浏览器的返回功能可以用栈来实现,当前浏览的页面我们叫它为栈顶元素,跳转到一个新页面我们叫元素入栈,点击“返回”按钮我们叫元素出栈,当然出栈前提是栈里要有元素,比如在浏览器里,如果已经返回到了最开始的页面,那就无法返回了。栈有一个重要的性质,就是先进后出,First In Last Out(FIL
阅读全文
摘要:1.队列的性质(先进先出): 新元素插入队尾(新来的同学站在最后面) 出队方案唯一(队伍买饭的先后顺序确定) 队首元素先出(站在前面的同学先买饭) 2.进队,出队,删除等操作的实现 3.循环队列: 前面讲到的队列实现方式有一个问题:“假上溢”。什么叫“假上溢”呢?回忆一下之前的插入队列的代码: 当
阅读全文
摘要:问题: Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exi
阅读全文
摘要:题目: According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician J
阅读全文
摘要:问题: Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and
阅读全文
摘要:题目: Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the
阅读全文
摘要:题目: Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].
阅读全文
摘要:new int;//开辟一个存放整数的存储空间,返回一个指向该存储空间的地址(即指针) new int(100);//开辟一个存放整数的空间,并指定该整数的初值为100,返回一个指向该存储空间的地址 new char[10];//开辟一个存放字符数组(包括10个元素)的空间,返回首元素的地址 new int[5][4];//开辟一个存放二维整型数组(大小为5*4)的空间,返回首...
阅读全文
摘要:题目: Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Given num = 16, return true. Given num = 5, retur
阅读全文
摘要:题目: Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it without using any loop / recursion? 答案: 判断一个数
阅读全文
摘要:问题: Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: begin t
阅读全文
摘要:问题: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is l
阅读全文
摘要:题目: Given an integer, write a function to determine if it is a power of two. 答案: 2的幂有两个特点: 1)大于0 2)二进制形式都是首位为1,其余位为0,因此n&(n-1)等于0
阅读全文