摘要: 内容全部来自编程之法:面试和算法心得一书,实现是自己写的使用的是java 题目描述 输入n个整数,输出其中最小的k个。 分析与解法 解法一 要求一个序列中最小的k个数,按照惯有的思维方式,则是先对这个序列从小到大排序,然后输出前面的最小的k个数。 至于选取什么的排序方法,我想你可能会第一时间想到快速 阅读全文
posted @ 2018-01-10 17:32 icychen 阅读(222) 评论(0) 推荐(0) 编辑
摘要: Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at 阅读全文
posted @ 2018-01-08 10:29 icychen 阅读(176) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest l 阅读全文
posted @ 2018-01-08 08:48 icychen 阅读(71) 评论(0) 推荐(0) 编辑
摘要: Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Note: The input array will only contain 0 and 1. The length 阅读全文
posted @ 2018-01-08 08:37 icychen 阅读(135) 评论(0) 推荐(0) 编辑
摘要: Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. Example 1: Example 2: 阅读全文
posted @ 2018-01-07 18:49 icychen 阅读(93) 评论(0) 推荐(0) 编辑
摘要: You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/ve 阅读全文
posted @ 2018-01-05 20:14 icychen 阅读(154) 评论(0) 推荐(0) 编辑
摘要: In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data. 阅读全文
posted @ 2018-01-05 20:03 icychen 阅读(183) 评论(0) 推荐(0) 编辑
摘要: Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the numbe 阅读全文
posted @ 2018-01-05 19:50 icychen 阅读(266) 评论(0) 推荐(0) 编辑
摘要: Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of th 阅读全文
posted @ 2018-01-05 16:06 icychen 阅读(171) 评论(0) 推荐(0) 编辑
摘要: Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might 阅读全文
posted @ 2018-01-05 15:35 icychen 阅读(132) 评论(0) 推荐(0) 编辑