编程面试十大算法总汇

1.字符串
如果IDE没有代码自动补全功能,所以你应该记住下面这些方法。
1、”‘“toCharArray() //获得字符串对应的char数组
2、Arrays.sort() //数组排序
3、Arrays.toString(char[] a) //数组转换成字符串
4、charAt(int x) //获得某个索引处的字符
5、length() //字符串长度
6、length //数组大小
“’”
2、链表
在JAVA中,链表的实现非常简单,每个节点Node都是有一个值val和指向下个节点的链接next.

class Node{
    int val;
    Node next;
    Node(int x){
        val=x;
        next=null;
        }
    }

链表两个著名的应用是栈Stack和队列Queue

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;
        }
    }
}

队列

class Queue{
    Node first,last;
    public void enqueue(Node n){
        if(first==null){
            first=n;
            last=first;
        }else{
            last.next=n;
            last=n;
        }
    }
    public void Node dequeue(){
        if(first==null){
            return null;
        }else{
            Node temp=new Node(first.val);
            first=first.next;
            if(last==temp)last=first;
            return temp;
        }
    }
}


3.树
这里的树通常是指二叉树,每个节点都包含一个左孩子节点和右孩子节点,像下面这样:

class TreeNode{
    int value;
    TreeNode left;
    TreeNode right;

下面是树的一些相关概念:
1.平衡VS非平衡:平衡二叉树中每个节点的左右子树深度相差至多为一。
2.满二叉树:除叶子节点以为的每个节点都有两个孩子。
3.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值