• 打印有序链表的公共部分



    import java.util.LinkedList;
    import java.util.List;

    public class Node {
        
        public static void printCommonPart(List<Integer> node1,List<Integer> node2) {
            System.out.println("common Part: ");
            for(int i=0,j=0;i<node1.size() &&j<node2.size();) {
                System.out.print(i+":");
                if(node1.get(i)<node2.get(j)) {
                    i++;
                }else if (node1.get(i)<node2.get(j)) {
                    j++;
                }else {
                    System.out.println(node1.get(i) +" ");
                    i++;
                    j++;
                }
            }
        }
        
        public static void main(String args[]) {
            List<Integer> node2 = new LinkedList<>();
            List<Integer> node1 = new LinkedList<>();
            node1.add(1);
            node1.add(3);
            node1.add(6);
            node1.add(81);
            node1.add(432);
            
            node2.add(2);
            node2.add(3);
            node2.add(11);
            node2.add(61);
            node2.add(81);
            node2.add(432);
            
            printCommonPart(node1,node2);
        }
        
    }

  • 相关阅读:
    怎样处理人际关系中的矛盾
    如何处理人际关系
    Python包含以下函数:
    与他人有效沟通的小技巧
    沟通时容易出现的问题
    如何在工作中提升自己
    第十三周进度报告
    第十二周学习进度
    团队绩效管理
    软件对标分析
  • 原文地址:https://www.cnblogs.com/interfaceone/p/7739202.html
Copyright © 2020-2023  润新知