摘要: 1.我们在网站上注册账号时,当填好用户名后,系统都会判断用户名是否已被使用,如果已被使用,系统就会提示该用户名已被注册。系统是如何检测用户名是否被使用的? 可以用哈希表来解决这个问题。哈希表又叫散列表,关键值通过哈希函数映射到数组上,查找时通过关键值直接访问数组。在上面的例子里,我们将用户名通过哈希 阅读全文
posted @ 2016-07-15 18:57 绵绵思远道 阅读(264) 评论(0) 推荐(0) 编辑
摘要: 1.浏览器的返回功能可以用栈来实现,当前浏览的页面我们叫它为栈顶元素,跳转到一个新页面我们叫元素入栈,点击“返回”按钮我们叫元素出栈,当然出栈前提是栈里要有元素,比如在浏览器里,如果已经返回到了最开始的页面,那就无法返回了。栈有一个重要的性质,就是先进后出,First In Last Out(FIL 阅读全文
posted @ 2016-07-14 22:05 绵绵思远道 阅读(437) 评论(0) 推荐(0) 编辑
摘要: 1.队列的性质(先进先出): 新元素插入队尾(新来的同学站在最后面) 出队方案唯一(队伍买饭的先后顺序确定) 队首元素先出(站在前面的同学先买饭) 2.进队,出队,删除等操作的实现 3.循环队列: 前面讲到的队列实现方式有一个问题:“假上溢”。什么叫“假上溢”呢?回忆一下之前的插入队列的代码: 当 阅读全文
posted @ 2016-07-14 16:09 绵绵思远道 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 问题: 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 阅读全文
posted @ 2016-07-09 22:08 绵绵思远道 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 题目: 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 阅读全文
posted @ 2016-07-09 15:59 绵绵思远道 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 问题: 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 阅读全文
posted @ 2016-07-09 14:09 绵绵思远道 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 题目: 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 阅读全文
posted @ 2016-07-05 16:37 绵绵思远道 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 题目: 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]. 阅读全文
posted @ 2016-07-05 16:30 绵绵思远道 阅读(123) 评论(0) 推荐(0) 编辑
摘要: new int;//开辟一个存放整数的存储空间,返回一个指向该存储空间的地址(即指针) new int(100);//开辟一个存放整数的空间,并指定该整数的初值为100,返回一个指向该存储空间的地址 new char[10];//开辟一个存放字符数组(包括10个元素)的空间,返回首元素的地址 new int[5][4];//开辟一个存放二维整型数组(大小为5*4)的空间,返回首... 阅读全文
posted @ 2016-07-03 23:24 绵绵思远道 阅读(481) 评论(0) 推荐(0) 编辑
摘要: 题目: 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 阅读全文
posted @ 2016-07-03 23:05 绵绵思远道 阅读(128) 评论(0) 推荐(0) 编辑