- 博客(10)
- 收藏
- 关注
转载 260. Single Number III
问题: Given an array of numbersnums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. For examp...
2016-04-21 11:28:00
115
转载 QuickSort
快速排序: 1 package com.wang.sort; 2 /* 3 * @tittle: bubbleSort 4 * @author: wwwglin 5 * @time 2016/04/20 6 */ 7 8 /* 9 * 思路:通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分...
2016-04-20 16:10:00
122
转载 BubbleSort
冒泡排序: 1 package com.wang.sort; 2 3 /* 4 * @tittle: bubbleSort 5 * @author: wwwglin 6 * @time 2016/04/20 7 */ 8 9 /* 10 * 思路:重复的遍历要排序的数组,每次遍历过程中从头至尾比较两个相邻的元素,若顺...
2016-04-20 15:12:00
157
转载 InsertSort
直接插入排序: 思想:每趟将一个待排序的元素作为关键字,按照其关键字值的大小插入到已经排好的部分序列的适当位置,知道插入而完成。 性能: 时间复杂度:最坏:O(n^2),最好O(n),平均O(2^n); 空间复杂度:O(1); 代码: 1 package com.wang.sort; 2 /* 3 * @...
2016-04-18 14:04:00
106
转载 Sort
最近总结一下排序算法相关知识。 排序算法的分类: 插入类排序:在已经有序的序列中,插入一个新的记录。 直接插入排序、折半插入排序、希尔排序。 交换类排序:交换类排序的核心是“交换”,即每一趟排序,都能通过一系列的“交换”动作,让一个记录排到它最终的位置上。 冒泡排序、快速排序。 ...
2016-04-18 13:55:00
132
转载 283. Move Zeroes
问题:Given an arraynums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements. 思考:开始想通过两层for循环,外层判断是否为0,内存将0用0之后的数字填补;再加一个循环,将被最后一位数...
2016-04-14 15:48:00
108
转载 104. Maximum Depth of Binary Tree
题目:Given a binary tree, find its maximum depth. 计算二叉树的深度。 解决:采用深度优先遍历。 1 package com.wang.test; 2 3 /* 4 * @tittle:104. Maximum Depth of Binary Tree 5 * @auther:wwwglin ...
2016-04-13 15:14:00
106
转载 136. Single Number
问题:Given an array of integers, every element appearstwiceexcept for one. Find that single one. 思考:运用双循环,微循环循环待比较数字,内层比较。增加一个flag表明是否匹配。 知识:flag的使用,以及比较时注意不要和自己比较。 解决: 1 package c...
2016-04-12 14:12:00
98
转载 292. Nim Game
问题: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 stones. The one who removes the last stone w...
2016-04-11 18:07:00
89
转载 338. Counting Bits
从今天开始,每天刷一道leetcode。 今天的题目很简单:Given a non negative integer numbernum. For every numbersiin the range0 ≤ i ≤ numcalculate the number of 1's in their binary representation and return them...
2016-04-11 17:46:00
117
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅