随笔分类 - 算法与数据结构
摘要:一个DNA序列由A/C/G/T四个字母的排列组合组成。G和C的比例(定义为GC-Ratio)是序列中G和C两个字母的总的出现次数除以总的字母数目(也就是序列长度)。在基因工程中,这个比例非常重要。因为高的GC-Ratio可能是基因的起始点。给定一个很长的DNA序列,以及要求的最小子序列长度,研究人员...
阅读全文
摘要:解题分析: 设f(m,n) 为m个苹果,n个盘子的放法数目,则先对n作讨论, 当n>m:必定有n-m个盘子永远空着,去掉它们对摆放苹果方法数目不产生影响。即if(n>m) f(m,n) = f(m,m) 当nm时,我们会return f...
阅读全文
摘要:1 import java.util.Scanner; 2 public class Main{ 3 public static void main(String[] args){ 4 Scanner scanner=new Scanner(System.in); ...
阅读全文
摘要:Jessi初学英语,为了快速读出一串数字,编写程序将数字转换成英文:如22:twentytwo,123:onehundredandtwentythree。说明:数字为正整数,长度不超过十位,不考虑小数,转化结果为英文小写;输出格式为twentytwo;非法数据请返回“error”;关键字提示:and...
阅读全文
摘要:现有一组砝码,重量互不相等,分别为m1、m2……mn;他们可取的最大数量分别为x1、x2……xn。现在要用这些砝码去称物体的重量,问能称出多少中不同的重量。 1 import java.util.HashSet; 2 import java.util.Scanner; 3 import java.u...
阅读全文
摘要:花了几个小时,终于实现了BST,虽然比较简单,但感觉还是不错。 测试代码 结果
阅读全文
摘要:数据结构中查找的知识点主要有以下三点 1、静态查找 1.1 顺序查找 1.2 有序表 1.2.1 二分查找 1.2.2 插值查找 2、动态查找 2.1 二叉排序树 2.2 平衡二叉树 2.3 B-和B+树 3、哈希查找 3.1 常用哈希函数 3.2 解决冲突的办法 1.2.1.1 非递归实现 实现思
阅读全文
摘要:思路: 1 将表达式转换成后缀表达式 2 利用栈计算后缀表达式 程序很罗嗦,有空再写一遍!
阅读全文
摘要:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.思路:首先想到的机试不断地减去一个数直到0为止,但是这样得复杂度为O(n),只得...
阅读全文
摘要:Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor...
阅读全文
摘要:Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:"((()))...
阅读全文
摘要:Letter Combinations of a Phone NumberGiven a digit string, return all possible letter combinations that the number could represent.A mapping of digit ...
阅读全文
摘要:Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:Elemen...
阅读全文
摘要:Question:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, wher...
阅读全文
摘要:Question:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: ...
阅读全文
摘要:Question:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the fa...
阅读全文
摘要:Question:Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root...
阅读全文
摘要:Question:Given 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 ...
阅读全文
摘要:Question:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the n...
阅读全文
摘要:Question:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the giv...
阅读全文