04 2016 档案
摘要:问题: Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two eleme
阅读全文
摘要:快速排序: 参考:http://blog.csdn.net/qarkly112649/article/details/35794097
阅读全文
摘要:直接插入排序: 思想:每趟将一个待排序的元素作为关键字,按照其关键字值的大小插入到已经排好的部分序列的适当位置,知道插入而完成。 性能: 时间复杂度:最坏:O(n^2),最好O(n),平均O(2^n); 空间复杂度:O(1); 代码:
阅读全文
摘要:最近总结一下排序算法相关知识。 排序算法的分类: 插入类排序:在已经有序的序列中,插入一个新的记录。 直接插入排序、折半插入排序、希尔排序。 交换类排序:交换类排序的核心是“交换”,即每一趟排序,都能通过一系列的“交换”动作,让一个记录排到它最终的位置上。 冒泡排序、快速排序。 选择类排序:每一趟排
阅读全文
摘要:问题:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. 思考:开始想通过两层for
阅读全文
摘要:题目:Given a binary tree, find its maximum depth. 计算二叉树的深度。 解决:采用深度优先遍历。
阅读全文
摘要:问题:Given an array of integers, every element appears twice except for one. Find that single one. 思考:运用双循环,微循环循环待比较数字,内层比较。增加一个flag表明是否匹配。 知识:flag的使用,以
阅读全文
摘要:问题:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 s
阅读全文
摘要:从今天开始,每天刷一道leetcode。 今天的题目很简单:Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in the
阅读全文

浙公网安备 33010602011771号