算法找数组中的特定元素
一个 int 数组,里面数据无任何限制,要求求出所有这样的数 a[i],其左边的数都小于等于它,右边的数都大于等于它。能否只用一个额外数组和少量其它空间实现。思路:如果能用两个辅助数组,那么相对来说简单一点,可定义数组Min和数组Max,其中Min[i]表示自a[i]之后的最小值(包括a[i]),Max[i]表示自a[i]之前元素...
算法数组中降序数列的最大长度
点击(此处)折叠或打开int MaxDesc(int param[], int length){ if(param==NULL||length<1) { return -1; &nb...
算法Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no duplicates in the array.Here are few examples.[1,3,5,6], 5 -> 2[1,3,5,6], 2 -> 1[1,3,5,6], 7 -> 4[1,3,5,6], 0 -> 0...
算法Set Matrix Zeroes
点击(此处)折叠或打开public class Solution { public void setZeroes(int[][] matrix) { boolean firstRowZero = false; ...
算法Valid Parentheses
点击(此处)折叠或打开public static boolean isValid(String s) { HashMap<Character, Character> map = new HashMap<Character, Character>(); map.put(\'(\', \')\'); map....
算法合并排序数组
点击(此处)折叠或打开public class Solution { public void merge(int A[], int m, int B[], int n) { while(m > 0 && n > 0){ ...
算法3Sum Closest
import java.util.Arrays; public class ThreeSumClosest { private int closest; private boolean needInit; &...
算法4Sum
fourSum: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.No...
算法3Sum
[cpp] view plaincopyclass Solution { public: vector<vector<int> > threeSum(vector<int> &num) { // Start t...
算法插入间隔
Problem:Given a set of non-overlapping & sorted intervals, insert a new interval into the intervals (merge if necessary).Example 1:Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9].Example 2:Given [1,2],[3,5],[6,7],[8,10],[12,16], insert and merge [4,9] in as [1,...
算法正则表达式
给定通配符*表达的意思是匹配0个或多个任意字符。如abc* 匹配的字符串为以abc开头的任意字符串..实现函数bool match(char* p,char*s)其中p为模式串(含*)s为匹配串,按照题意判断二者是否匹配,如果匹配返回true,不匹配返回false思路:1。 递归,枚举*代表的字符数目,从0到n,然后用递归解决:...
单源无权最短路径举例——字梯问题
1/**//* 2最短路径的一个举例: 3 4问题描述:在字梯游戏中,每一个词语都是通过将字梯的前一个词改变一个字母形成的。 5例如,我们可以通过一系列的单字母替换将zero转换成five:zero, hero, here, hire, fire, five。 6 &...
算法寻找数组中的第二大数
方法一:[cpp] view plaincopy#include "stdio.h" #include "stdlib.h" //初始化最大值为a[0],次大值为a[1],遍历一次,每次比较并更新最大值和次大值,最后就可以得到次大值。 ...
算法搜狗笔试题链表合并
实现一个队链表排序的算法,C/C++可以使用std::list<int>,Java使用LinkedList<Integer>要求先描述算法,然后再实现,算法效率尽可能高效。主要考察链表的归并排序。要点:需要使用快、慢指针的方法,找到链表的的中间节点,然后进行二路归并排序[cpp] view plaincopytypedef&nbs...
算法搜狗笔试题加减法
一种计算机,其有如下原子功能:1、赋值 a=b2、+1操作,++a; a+1;3、循环,但是只支持按次数的循环 for(变量名){/*循环里面对变量的修改不影响循环次数*/}4、只能处理0和正整数5、函数调用 fun(参数列表)请用伪代码的形式分别在这个计算机上编程实现变量的加法、减法、...
算法微软100题数字查找
题:假设你有一个用1001个整数组成的数组,这些整数是任意排列的,但是你知道所有的整数都在1到1000(包括1000)之间。此外,除一个数字出现两次外,其他所有数字只出现一次。假设你只能对这个数组做一次处理,用一种算法找出重复的那个数字。如果你在运算中使用了辅助的存储方式,那么你能找到不用这种方式的算法吗?分...
算法线索二叉树的建立和遍历
点击(此处)折叠或打开typedef struct BiThrNode{ char data; struct BiThrNode *lchild, *rchild; PointerTag LTag; Poin...
算法根据树的前序遍历构建二叉树
点击(此处)折叠或打开typedef struct BiTNode{ char data; struct BiTNode *lchild, *rchild;}BiTNode, *BiTree;void CreateBiTree(BiTree *T)...
算法求交集
struct node { int elem; node* next; }; void difference(node** LA , node* LB)...
算法一百以内的素数
struct prime_number_node { int prime_number; prime_number_node* next; }; int calc_prime_number() {&n...