![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
NicolasYan
这个作者很懒,什么都没留下…
展开
-
A*寻路算法
你是否在做一款游戏的时候想创造一些怪兽或者游戏主角,让它们移动到特定的位置,避开墙壁和障碍物呢?如果是的话,请看这篇教程,我们会展示如何使用A星寻路算法来实现它!在网上已经有很多篇关于A星寻路算法的文章,但是大部分都是提供给已经了解基本原理的高级开发者的。本篇教程将从最基本的原理讲起。我们会一步步讲解A星寻路算法,幷配有很多图解和例子。不管你使用的是什么编程语言或者转载 2014-11-26 10:40:35 · 872 阅读 · 0 评论 -
2N+1个数,除了其中一个数之外,其他均为两两成对,寻找这个落单的数
有2n+1个数,其中2n个数两两成对,1个数落单,找出这个数。要求O(n)的时间复杂度,O(1)的空间复杂度。进阶问题:如果有2n+2个数,其中有2个数落单,该怎么办?原创 2016-01-21 18:25:05 · 1564 阅读 · 0 评论 -
二叉树逐行打印,同时打印每行时需要换行
二叉树逐层遍历依靠一个队列先进后出的特点进行算法设计如下:void BinaryTreeTraversal(const BinaryTreeNode* head){ if(head==NULL) return; Queue queue; queue.push(head); while (queue.size()!=0)原创 2016-02-03 14:26:25 · 1142 阅读 · 0 评论 -
快速排序的非递归实现
直接上代码,递归转换成为非递归主要依靠一个栈来实现。#include#include#include#include#includeusing namespace std;/**把数组分为两部分,轴pivot左边的部分都小于轴右边的部分**/templateint partition(vector& vec,int low,int high){ Comparable原创 2016-03-18 10:22:42 · 484 阅读 · 0 评论 -
二进制移位实现加减乘除
1. 题目描述如何使用位操作分别实现整数的加减乘除四种运算?2. 解决方案需要熟练掌握一些常见功能的位操作实现,具体为: 常用的等式:-n = ~(n-1) = ~n+1 获取整数n的二进制中最后一个1:n&(-n) 或者 n&~(n-1),如:n=010100,则-n=101100,n&(-n)=000100 去掉整数n的二进制中最后一个1原创 2016-03-10 00:41:56 · 14249 阅读 · 1 评论 -
算法:Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add原创 2016-09-13 10:50:35 · 370 阅读 · 0 评论 -
算法:Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 0011100原创 2016-09-13 10:52:52 · 577 阅读 · 0 评论 -
算法:Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9原创 2016-09-13 10:57:08 · 432 阅读 · 0 评论 -
算法:Range Sum Query 2D - Immutable
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).Given matrix = [ [3, 0, 1, 4, 2],原创 2016-09-13 11:00:14 · 443 阅读 · 0 评论 -
算法:Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value./** *原创 2016-09-13 11:02:46 · 604 阅读 · 0 评论 -
算法:Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like:原创 2016-09-13 11:05:03 · 532 阅读 · 0 评论 -
一个数组中,除两个元素其余都出现了两次,找出这两个元素
题目:在一个数组中除两个数字只出现1次外,其它数字都出现了2次, 要求尽快找出这两个数字。 考虑下这个题目的简化版——数组中除一个数字只出现1次外,其它数字都成对出现,要求尽快找出这个数字。这个题目在之前的《位操作基础篇之位操作全面总结》中的“位操作趣味应用”中就已经给出解答了。根据异或运算的特点,直接异或一次就可以找出这个数字。 现在数组中有两个数字只出现1次,直接异原创 2014-12-09 01:02:04 · 2389 阅读 · 0 评论 -
算法--根据二叉树前序和中序遍历序列,求后续遍历序列
根据二叉树前序和中序遍历序列,求后续遍历序列。原创 2014-11-24 10:11:42 · 828 阅读 · 0 评论 -
BitMap算法
概述所谓bitmap就是用一个bit位来标记某个元素对应的value,而key即是这个元素。由于采用bit为单位来存储数据,因此在可以大大的节省存储空间算法思想32位机器上,一个整形,比如int a;在内存中占32bit,可以用对应的32个bit位来表示十进制的0-31个数,bitmap算法利用这种思想处理大量数据的排序与查询优点转载 2014-11-27 09:35:01 · 595 阅读 · 0 评论 -
算法--将字符串中*号移到左边,字母移到右边,保持字母相对顺序不变
这是一个O(n)时间复杂度实现的,原创 2014-11-24 17:06:48 · 1844 阅读 · 0 评论 -
算法--判断一个数字序列是否为二叉排序树的后续遍历
判断一个数字序列是否为二叉排序树的后续遍历,其实就是一个递归,算法很短原创 2014-11-24 10:02:38 · 1556 阅读 · 0 评论 -
算法--大数相加问题
计算两个难以用基本数据类型表示的大数相加问题,当然本例并没有考虑正负号等问题,只是一个简单版本的……原创 2014-11-24 09:51:26 · 899 阅读 · 0 评论 -
BM字符串匹配算法
BM算法可能是相对来说,算法效率最高的一种,一般是KMP算法的3~5倍。 BM算法是从后缀比较法开始的。就是给出的算法(1)代码。然而,普通的后缀比较法一般移动只有1。而BM算法其实是对后缀蛮力匹配算法的改进。为了实现更快移动模式串,BM算法定义了两个规则,好后缀规则和坏字符规则。用好后缀和坏字符可以大大加快模式串的移动距离,不是简单的 j,而是j =max (shift(好原创 2014-11-27 13:53:04 · 815 阅读 · 0 评论 -
链表逆向交替合并问题
问题描述:假设有两个单链表A和B,不带头节点,且长度一样,示例如下:A: 1->2->3->4B: a->b->c->d请逆转交替合并两个链表,示例结果如下:4->d->3->c->2->b->1->a#include #include struct Node{ char c; struct Node* next;};/*构造链表hea原创 2014-11-27 14:14:18 · 549 阅读 · 0 评论 -
算法--Fire Net问题
Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall.A blockhouse is a small castle th原创 2014-11-24 10:18:21 · 834 阅读 · 0 评论 -
Trie树的编程实现,用于计算字符串出现次数,求公共前缀字符串等问题
1. 什么是trie树 1.Trie树 (特例结构树) Trie树,又称单词查找树、字典树,是一种树形结构,是一种哈希树的变种,是一种用于快速检索的多叉树结构。典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计。它的优点是:最大限度地减少无谓的字符串比较,查询效率比哈希表高。 Trie的核心思想是原创 2014-11-26 13:11:50 · 940 阅读 · 0 评论 -
一道微软笔试题
算法思路:先将链表后半部分逆序原创 2014-11-24 09:34:15 · 818 阅读 · 0 评论 -
算法--计算两个绝对路径之间的相对路径
例如有两个绝度路径分别为"/qihoo/app/1/2/jtest.c"和原创 2014-11-24 09:40:52 · 1793 阅读 · 0 评论 -
Find The First Non Repeated Character In A String : Technical Interview Question
Logic As we know a non repeated character occurs only once in the string , so if we store the number of timeseach alphabet appears in the string , it would help us identifying which characters原创 2016-09-01 15:36:16 · 538 阅读 · 0 评论