算法
文章平均质量分 51
来自星星的松子
一个有理想的逗比。
展开
-
排序算法-冒泡排序
一、冒泡排序的实现步骤(1)比对相邻元素的值,如果前者比后者大,则交换它们; (2)对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对。这步做完后,最后的元素会是最大的数。 (3)针对所有的元素重复以上的步骤,除了最后一个。 (4)持续每次对越来越少的元素重复上面的步骤,直到没有任何一对数字需要比较。原创 2016-03-03 10:30:51 · 257 阅读 · 0 评论 -
LeetCode - Two Sum
QuestionLink : https://leetcode.com/problems/two-sum/ 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原创 2016-04-11 17:38:58 · 226 阅读 · 0 评论 -
LeetCode - Delete Node in a Linked List
QuestionLink : https://leetcode.com/problems/delete-node-in-a-linked-list/Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.原创 2016-04-14 20:13:29 · 263 阅读 · 0 评论 -
LeetCode - Binary Tree Level Order Traversal
QuestionGiven a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).原创 2016-04-14 20:42:35 · 259 阅读 · 0 评论 -
LeetCode - Word Pattern
QuestionLink : https://leetcode.com/problems/word-pattern/Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a原创 2016-04-28 23:46:46 · 361 阅读 · 0 评论 -
LeetCode - ZigZag Conversion
QuestionLink : https://leetcode.com/problems/zigzag-conversion/The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this...原创 2016-04-16 22:51:39 · 256 阅读 · 0 评论 -
LeetCode - Majority Element
QuestionLink : https://leetcode.com/problems/majority-element/Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.原创 2016-04-16 23:45:52 · 263 阅读 · 0 评论 -
LeetCode - Power of Four
QuestionLink : https://leetcode.com/problems/power-of-four/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原创 2016-04-19 22:21:39 · 371 阅读 · 0 评论 -
LeetCode - Nim Game
QuestionLink : https://leetcode.com/problems/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 s原创 2016-04-19 22:52:01 · 659 阅读 · 0 评论 -
LeetCode - Power of Three
Given an integer, write a function to determine if it is a power of three.原创 2016-04-21 11:15:29 · 314 阅读 · 0 评论 -
LeetCode - Ugly Number
QuestionLink : Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.原创 2016-04-21 11:43:17 · 318 阅读 · 0 评论 -
LeetCode - Reverse String
QuestionLink : https://leetcode.com/problems/reverse-string/Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.原创 2016-04-22 23:11:23 · 421 阅读 · 0 评论 -
LeetCode - Add Two Numbers
QuestionLink:https://leetcode.com/problems/add-two-numbers/ You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain原创 2016-04-11 17:45:13 · 307 阅读 · 0 评论 -
LeetCode - Add Digits
QuestionLink:https://leetcode.com/problems/add-digits/ Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.原创 2016-04-11 18:58:38 · 265 阅读 · 0 评论 -
LeetCode - Add Binary
QuestionLink:https://leetcode.com/problems/add-binary/ Given two binary strings, return their sum (also a binary string).原创 2016-04-11 19:52:59 · 336 阅读 · 0 评论 -
排序算法-插入排序
介绍 插入排序(Insertion Sort)是一种简单直观的排序算法。它的工作原理是通过构建有序序列,对于未排序数据,在已排序序列中从后向前扫描,找到相应位置并插入。插入排序在实现上,通常采用in-place排序(即只需用到O(1)的额外空间的排序),因而在从后向前扫描过程中,需要反复把已排序元素逐步向后挪位,为最新元素提供插入空间。原创 2016-03-03 10:35:30 · 299 阅读 · 0 评论 -
排序算法-选择排序
介绍 选择排序(Selection sort)是一种简单直观的排序算法。 它的工作原理如下。首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾。以此类推,直到所有元素均排序完毕。 选择排序的主要优点与数据移动有关。如果某个元素位于正确的最终位置上,则它不会被移动。选择排序每次交换一对元素,它们当中至原创 2016-03-03 10:42:16 · 305 阅读 · 0 评论 -
数据结构-BST、AVL、二叉堆、B树、B+树、红黑树
总结了数据结构中树的一些常见的类型。一、线索二叉树对于n个结点的二叉树,在二叉链存储结构中有n+1个空链域,利用这些空链域存放在某种遍历次序下该结点的前驱结点和后继结点的指针,这些指针称为线索,加上线索的二叉树称为线索二叉树。二、二叉查找树(BST)二叉查找树又叫二叉排序树,二叉搜索树。二叉排序树或者是一棵空树,或者是具有下列性质的二叉树原创 2016-03-03 00:25:45 · 3183 阅读 · 0 评论 -
排序算法-归并排序
介绍归并排序(英语:Merge sort,或mergesort),是创建在归并操作上的一种有效的排序算法,效率为O(n log n)。该算法是采用分治法(Divide and Conquer)的一个非常典型的应用,且各层分治递归可以同时进行。归并操作归并操作也叫归并算法,指的是将两个已经排序的序列合并成一个序列的操作。归并排序算法依赖归并操作。原创 2016-03-04 21:22:59 · 353 阅读 · 0 评论 -
排序算法-堆排序
堆排序(Heapsort)堆排序是指利用堆这种数据结构所设计的一种排序算法。 堆积是一个近似完全二叉树的结构,并同时满足堆积的性质:即子结点的键值或索引总是小于(或者大于)它的父节点。算法过程堆排序(HeapSort):移除位在第一个数据的根节点,并做最大堆调整的递归运算。原创 2016-03-04 21:08:45 · 227 阅读 · 0 评论 -
排序算法-桶排序和计数排序
桶排序桶排序(Bucket sort)或所谓的箱排序,也是一种排序算法。 其工作的原理是将数组分到有限数量的桶子里。每个桶子再个别排序(有可能再使用别的排序算法或是以递归方式继续使用桶排序进行排序)。桶排序是鸽巢排序的一种归纳结果。当要被排序的数组内的数值是均匀分配的时候,桶排序使用线性时间(Θ(n))。但桶排序并不是比较排序,他不受到O(n log n)下限的影响。原创 2016-03-05 13:09:03 · 438 阅读 · 0 评论 -
排序算法-基数排序
基数排序(英语:Radix sort)是一种非比较型整数排序算法,其原理是将整数按位数切割成不同的数字,然后按每个位数分别比较。原创 2016-03-07 16:35:00 · 331 阅读 · 0 评论 -
排序算法-希尔排序
一、介绍 希尔排序,也称递减增量排序算法,是插入排序的一种更高效的改进版本。希尔排序是非稳定排序算法。原创 2016-03-07 16:38:04 · 302 阅读 · 0 评论 -
排序算法-快速排序
快速排序使用分治法(Divide and conquer)策略来把一个序列(list)分为两个子序列(sub-lists)。原创 2016-03-11 13:09:33 · 365 阅读 · 0 评论 -
LeetCode - Best Time to Buy and Sell Stock
QuestionLink : https://leetcode.com/problems/best-time-to-buy-and-sell-stock/Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complet原创 2016-04-13 15:31:36 · 245 阅读 · 0 评论 -
LeetCode - Balanced Binary Tree
QuestionGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never di原创 2016-04-13 14:34:33 · 252 阅读 · 0 评论 -
算法:寻找两个单项链表的交点
问题:寻找两个单项链表的交点。原创 2016-02-28 14:04:29 · 2753 阅读 · 1 评论