码农福利程序开发最常用的10大算法.docVIP

  • 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

文档评论(0)

1亿VIP精品文档

相关文档