- 0
- 0
- 约6.78千字
- 约 14页
- 2017-09-02 发布于浙江
- 举报
码农福利程序开发最常用的10大算法
码农福利:程序开发最常用的10大算法
1.String/Array/Matrix
在Java中,String是一个包含char数组和其它字段、方法的类。如果没有IDE自动完成代码,下面这个方法大家应该记住:
toCharArray() //get char array of a String
Arrays.sort() //sort an array
Arrays.toString(char[] a) //convert to string
charAt(int x) //get a char at the specific index
length() //string length
length //array size
substring(int beginIndex)
substring(int beginIndex, int endIndex)
Integer.valueOf()//string to integer
String.valueOf()/integer to string
String/arrays很容易理解,但与它们有关的问题常常需要高级的算法去解决,例如动态编程、递归等。
下面列出一些需要高级算法才能解决的经典问题:
●Evaluate Reverse Polish Notation
●Longest Palindromic Substring
●单词分割
●字梯
●Median of Two Sorted Arrays
●正则表达式匹配
●合并间隔
●插入间隔
●Two Sum
●3Sum
●4Sum
●3Sum Closest
●String to Integer
●合并排序数组
●Valid Parentheses
●实现strStr()
●Set Matrix Zeroes
●搜索插入位置
●Longest Consecutive Sequence
●Valid Palindrome
●螺旋矩阵
●搜索一个二维矩阵
●旋转图像
●三角形
●Distinct Subsequences Total
●Maximum Subarray
●删除重复的排序数组
●删除重复的排序数组2
●查找没有重复的最长子串
●包含两个独特字符的最长子串
●Palindrome Partitioning
2.链表
在Java中实现链表是非常简单的,每个节点都有一个值,然后把它链接到下一个节点。
class Node {
int val;
Node next;
Node(int x) {
val = x;
next = null;
}
}
比较流行的两个链表例子就是栈和队列。
栈(Stack)
class Stack{
Node top;
public Node peek(){
if(top != null){
return top;
}
return null;
}
public Node pop(){
if(top == null){
return null;
}else{
Node temp = new Node(top.val);
top = top.next;
return temp;
}
}
public void push(Node n){
if(n != null){
n.next = top;
top = n;
}
}
}
队列(Queue)
class Queue{
Node first, last;
nbsp;
public void enqueue(Node n){
if(first == null){
first = n;
last = first;
}else{
last.next = n;
last = n;
}
}
nbsp;
public Node dequeue(){
if(first == null){
return null;
}else{
Node temp = new Node(first.v
您可能关注的文档
最近下载
- 浙江省金华市2023年中考数学试卷 .pdf VIP
- 英语专四新题型选词填空做题技巧.ppt VIP
- 2026年广东省普通高中学业水平合格性考试英语试卷含答案.pdf VIP
- 英菲尼迪QX70说明书|Infiniti QX70 Owner's Manual.pdf
- 光合作用的原理和应用课件【新教材】人教版高中生物必修一.pptx VIP
- 概率论与数理统计教学教案.doc VIP
- 统编版(2024)七年级上册道德与法治期末复习模拟试卷 3套(含答案).pdf
- 倾斜摄影三维建模项目设计方案.pdf VIP
- 脑胶质瘤诊疗规范2025年版.docx VIP
- 2025年海南省中考化学真题(含答案).pdf
原创力文档

文档评论(0)