算法
文章平均质量分 69
whyalwaysmea
I know the way
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C … 26 -> Z 27 -> AA 28 -> A原创 2016-08-03 09:43:14 · 377 阅读 · 0 评论 -
归并排序【MergeSort】
归并排序 归并排序(MERGE-SORT)是利用归并的思想实现的排序方法,该算法采用经典的分治(divide-and-conquer)策略(分治法将问题分(divide)成一些小的问题然后递归求解,而治(conquer)的阶段则将分的阶段得到的各答案”修补”在一起,即分而治之)。 首先我们可以思考:如何将两个有序的序列合并,并且合并后依然有序呢? 这个比较简单,我们只需要用两个指针,...原创 2018-04-16 23:43:46 · 331 阅读 · 0 评论 -
选择排序 【SelectionSort】
选择排序 假设初始的数组是[5,4,7,2] 以从小到大排序为例,我们可以将数组分为两个区域,一个是无序区,一个是有序区,在一开始所有的数据都在无序区。 进行第一轮排序,对无序区的数组[5,4,7,2]进行遍历,记录最小值2,然后将它与第0个元素进行位置交换。此时无序数组[4,7,5],有序数组[1],原本的数组[1,4,7,5] 进行第二轮排序,对无序区的数组[4,7,5]进行遍历,记...原创 2018-04-16 23:43:14 · 447 阅读 · 0 评论 -
插入排序 【InsertionSort】
插入排序 插入排序的工作方式像排序一手扑克牌。 假设左手的牌是排序好的,桌面上的是未知的牌 1. 开始时,我们的左手为空并且桌子上的牌面向下。 2. 然后,我们每次从桌子上拿走一张牌并将它插入左手正确的位置。 为了找到插入的正确位置,我们将要插入的牌与左手的牌挨着比较,直接找到合适的位置并插入进去。 在实际的实现过程中,我们可以将数组的第0个元素看成是已经排序好的,然后从第二个元素开始进...原创 2018-04-16 23:42:40 · 333 阅读 · 0 评论 -
冒泡排序【BubbleSort】
冒泡排序 假设初始的数组是[5,4,7,2] 以从小到大排序为例: 将第0个元素与第一个元素进行比较, 5 > 4, 所以交换位置, 此时[4,5,7,2] 将第1个元素与第二个元素进行比较, 5 < 7, 所以保持,此时[4,5,7,2] 将第2个元素与第三个元素进行比较, 7 > 2, 所以交换位置, 此时[4,5,2,7] 这样就经过了一轮的冒泡,最后...原创 2018-04-16 23:41:11 · 441 阅读 · 0 评论 -
Pascal's Triangle II
Description Given an index k, return the kth row of the Pascal’s triangle. For example, given k = 3, Return [1,3,3,1] Note: Could you optimize your algorithm to use only O(k) extra space? Disc...原创 2018-03-05 16:10:02 · 228 阅读 · 0 评论 -
Find Mode in Binary Search Tree
Description Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is defined as follows: The left subtree of ...原创 2018-03-05 15:40:11 · 276 阅读 · 0 评论 -
Find Smallest Letter Greater Than Target
Description Given a list of sorted characters letters containing only lowercase letters, and given a target letter target, find the smallest element in the list that is larger than the given target. ...原创 2018-03-16 18:12:04 · 259 阅读 · 0 评论 -
Guess Number Higher or Lower
Description We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I’ll tell you whether the number...原创 2018-02-06 16:26:52 · 250 阅读 · 0 评论 -
二叉搜索树(Binary Search Tree)
二叉搜索树(Binary Search Tree) 二叉搜索树(BST)也称为有序二叉树、排序二叉树。 是指一棵空树或者具有下列性质的二叉树: 1. 若任意节点的左子树不空,则左子树上所有结点的值均小于它的根结点的值 2. 任意节点的右子树不空,则右子树上所有结点的值均大于它的根结点的值 3. 任意节点的左、右子树也分别为二叉查找树。 4. 没有键值相等的节点。 二叉查找树相比...原创 2018-02-28 16:34:09 · 516 阅读 · 0 评论 -
Two Sum
Description Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not ...原创 2018-02-08 15:41:01 · 236 阅读 · 0 评论 -
Valid Perfect Square
Description Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library function such as sqrt. Example 1: Inp...原创 2018-02-07 15:54:24 · 195 阅读 · 0 评论 -
Count and Say
Description The count-and-say sequence is the sequence of integers with the first five terms as following: 1. 1 2. 11 3. 21 4. 1211 5. 111221 1 is read off as "one 1" or 11.原创 2018-01-19 16:42:21 · 209 阅读 · 0 评论 -
Base 7
Description Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: “202” Example 2: Input: -7 Output: “-10” Discuss 题意: 题意比较简单,就是把十进制转换成7进制,用st原创 2018-01-31 17:06:15 · 587 阅读 · 0 评论 -
Invert Binary Tree
Description Invert a binary tree. to Discuss 题意: 题意还是比较清楚的,就是翻转二叉树 思考: 直接使用递归,递归到后面的时候进行左右的交换 另一种思路: 可以采用广度优先遍历(Breadth First Search) 广度优先遍历算法,又叫宽度优先遍历,或横向优先遍历,是从根节点开始,沿着树的宽度遍历树的节点。原创 2018-01-23 17:26:38 · 236 阅读 · 0 评论 -
Reverse Vowels of a String -- 颠倒字符串中的元音
一个根据条件来转换字符串顺序的算法题目原创 2016-04-25 22:35:17 · 741 阅读 · 0 评论 -
Power of Four and Power of Three - 4的次方和3的次方
Power of Four原创 2016-05-25 16:33:11 · 531 阅读 · 0 评论 -
Add Digits -- 增加数字
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. 给出一个正整数,对它的每一位进行相加,直到结果是个一位的数字。原创 2016-06-13 17:52:42 · 634 阅读 · 0 评论 -
两个单链表相交的一系列问题
两个单链表相交的一系列问题 【题目】在本题中,单链表可能有环,也可能无环。给定两个单链表的头节点head1和head2,这两个链表可能相交,也可能不相交。请实现一个函数,如果两个链表相交,则返回相交的第一个节点;如果不相交,则返回null。 【要求】如果链表1的长度为N,链表2的长度为M,时间复杂度请达到O(N+M),额外空间复杂度请达到O(1) 思考 其实这道题目是一系列的问题,...原创 2018-06-05 16:01:59 · 386 阅读 · 0 评论
分享