链表结构

  • 单链表的节点结构  由以下结构的节点依次连接起来所形成的链叫单链表结构
Clas Node<V>{ V value; Node next;
} 
  • 双链表的节点结构 由以下结构的节点依次连接起来所形成的链叫双链表结构
Clas Node<V>{ V value; Node next; Node last;
} 
  • 单链表和双链表结构只需要给定一个头部节点head,就可以找到剩下的所有的节点

反转单向和双向链表

  • [题目] 分别实现反转单向链表和反转双向链表的函数
  • [要求] 如果链表长度为N,时间复杂度要求为O(N),额外空间复杂度要求为 O(1)
package com.example.algorithm.demo.class04;public class Code02_ReverseList {public static class Node {public int value;public Node next;public Node(int data) {this.value = data;}}public static Node reverseList(Node head) {Node pre = null;Node next = null;while (head != null) {next = head.next;head.next = pre;pre = head;head = next;}return pre;}public static class DoubleNode {public int value;public DoubleNode last;public DoubleNode next;public DoubleNode(int data) {this.value = data;}}public static DoubleNode reverseList(DoubleNode head) {DoubleNode pre = null;DoubleNode next = null;while (head != null) {next = head.next;head.next = pre;head.last = next;pre = head;head = next;}return pre;}public static void printLinkedList(Node head) {System.out.print("Linked List: ");while (head != null) {System.out.print(head.value + " ");head = head.next;}System.out.println();}public static void printDoubleLinkedList(DoubleNode head) {System.out.print("Double Linked List: ");DoubleNode end = null;while (head != null) {System.out.print(head.value + " ");end = head;head = head.next;}System.out.print("| ");while (end != null) {System.out.print(end.value + " ");end = end.last;}System.out.println();}public static void main(String[] args) {Node head1 = new Node(1);head1.next = new Node(2);head1.next.next = new Node(3);printLinkedList(head1);head1 = reverseList(head1);printLinkedList(head1);DoubleNode head2 = new DoubleNode(1);head2.next = new DoubleNode(2);head2.next.last = head2;head2.next.next = new DoubleNode(3);head2.next.next.last = head2.next;head2.next.next.next = new DoubleNode(4);head2.next.next.next.last = head2.next.next;printDoubleLinkedList(head2);printDoubleLinkedList(reverseList(head2));}}

打印两个有序链表的公共部分

  • [题目] 给定两个有序链表的头指针head1和head2,打印两个链表的公共部分。
  • [要求] 如果两个链表的长度之和为N,时间复杂度要求为O(N),额外空间复杂度要求为O(1)
  • [思路] head1指向第一个有序链表,head2指向第二个有序链表,比较元素的大小,如果相等打印元素的数值。否则,指针指向的元素的数值小的率先移动,比较大小,元素数值小的移动
package com.example.algorithm.demo.class04;public class Code03_PrintCommonPart {public static class Node{public int value;public Node next;public Node(int data){this.value = data;}}public static void printCommonPart(Node head1,Node head2){System.out.println("Common Part: ");while (head1 != null && head2 != null){if (head1.value < head2.value){head1 = head1.next;} else if(head2.value < head1.value){head2 = head2.next;} else{System.out.print(head1.value+" ");head1 = head1.next;head2 = head2.next;}}System.out.println();}public static void printLinkedList(Node node) {System.out.print("Linked List: ");while (node != null) {System.out.print(node.value + " ");node = node.next;}System.out.println();}public static void main(String[] args) {Node node1 = new Node(2);node1.next = new Node(3);node1.next.next = new Node(5);node1.next.next.next = new Node(6);Node node2 = new Node(1);node2.next = new Node(2);node2.next.next = new Node(5);node2.next.next.next = new Node(7);node2.next.next.next.next = new Node(8);printLinkedList(node1);printLinkedList(node2);printCommonPart(node1, node2);}
}

面试时链表解题的方法论

  • 1)对于笔试,不用太在乎空间复杂度,一切为了时间复杂度
  • 2)对于面试,时间复杂度依然放在第一位,但是一定要找到空间最省的方法

重要技巧:

  • 1)额外数据结构记录(哈希表等)
  • 2)快慢指针

快速找到链表的中点

  • 快慢指针的方式,慢指针每次移动一个长度,快指针每次移动二个长度。当快指针到达链表的末尾,慢指针到达链表的中点。
  • 问题:奇数偶数判定不一样的,需要细节定制

回文结构

  • 将链表的后半部分放到栈里边,存储的是后半部分数据的逆序
  • 面试考虑内存空间,进一步优化。找到链表的中点之后,将中点的下一个指针指向nullptr,然后将中点之后的节点的下一个指针进行逆向排序,如下图所示,主要目的是为了节省空间。然后两个指针一个从头 一个从尾进行依次读取数据进行比较,如果一致满足回文结构。但是最后需要将链表进行还原,恢复成 1 -> 2 -> 3 -> 2 ->1 的结构
  • 1 -> 2 -> 3 <- 2 <- 1
  • 第二种方式 初始化的时候,将right初始化为head->next;将cur初始化为head节点;主要目的是为了将慢指针移动到中心节点的右边,然后将中心节点开始的位置到null这段区间的节点都拷贝到栈空间
package class04;import java.util.Stack;public class Code04_IsPalindromeList {public static class Node {public int value;public Node next;public Node(int data) {this.value = data;}}// need n extra spacepublic static boolean isPalindrome1(Node head) {Stack<Node> stack = new Stack<Node>();Node cur = head;while (cur != null) {stack.push(cur);cur = cur.next;}while (head != null) {if (head.value != stack.pop().value) {return false;}head = head.next;}return true;}// need n/2 extra spacepublic static boolean isPalindrome2(Node head) {if (head == null || head.next == null) {return true;}Node right = head.next;Node cur = head;while (cur.next != null && cur.next.next != null) {right = right.next;cur = cur.next.next;}Stack<Node> stack = new Stack<Node>();while (right != null) {stack.push(right);right = right.next;}while (!stack.isEmpty()) {if (head.value != stack.pop().value) {return false;}head = head.next;}return true;}// need O(1) extra spacepublic static boolean isPalindrome3(Node head) {if (head == null || head.next == null) {return true;}Node n1 = head;Node n2 = head;while (n2.next != null && n2.next.next != null) { // find mid noden1 = n1.next; // n1 -> midn2 = n2.next.next; // n2 -> end}n2 = n1.next; // n2 -> right part first noden1.next = null; // mid.next -> nullNode n3 = null;while (n2 != null) { // right part convertn3 = n2.next; // n3 -> save next noden2.next = n1; // next of right node convertn1 = n2; // n1 moven2 = n3; // n2 move}n3 = n1; // n3 -> save last noden2 = head;// n2 -> left first nodeboolean res = true;while (n1 != null && n2 != null) { // check palindromeif (n1.value != n2.value) {res = false;break;}n1 = n1.next; // left to midn2 = n2.next; // right to mid}n1 = n3.next;n3.next = null;while (n1 != null) { // recover listn2 = n1.next;n1.next = n3;n3 = n1;n1 = n2;}return res;}public static void printLinkedList(Node node) {System.out.print("Linked List: ");while (node != null) {System.out.print(node.value + " ");node = node.next;}System.out.println();}public static void main(String[] args) {Node head = null;printLinkedList(head);System.out.print(isPalindrome1(head) + " | ");System.out.print(isPalindrome2(head) + " | ");System.out.println(isPalindrome3(head) + " | ");printLinkedList(head);System.out.println("=========================");head = new Node(1);printLinkedList(head);System.out.print(isPalindrome1(head) + " | ");System.out.print(isPalindrome2(head) + " | ");System.out.println(isPalindrome3(head) + " | ");printLinkedList(head);System.out.println("=========================");head = new Node(1);head.next = new Node(2);printLinkedList(head);System.out.print(isPalindrome1(head) + " | ");System.out.print(isPalindrome2(head) + " | ");System.out.println(isPalindrome3(head) + " | ");printLinkedList(head);System.out.println("=========================");head = new Node(1);head.next = new Node(1);printLinkedList(head);System.out.print(isPalindrome1(head) + " | ");System.out.print(isPalindrome2(head) + " | ");System.out.println(isPalindrome3(head) + " | ");printLinkedList(head);System.out.println("=========================");head = new Node(1);head.next = new Node(2);head.next.next = new Node(3);printLinkedList(head);System.out.print(isPalindrome1(head) + " | ");System.out.print(isPalindrome2(head) + " | ");System.out.println(isPalindrome3(head) + " | ");printLinkedList(head);System.out.println("=========================");head = new Node(1);head.next = new Node(2);head.next.next = new Node(1);printLinkedList(head);System.out.print(isPalindrome1(head) + " | ");System.out.print(isPalindrome2(head) + " | ");System.out.println(isPalindrome3(head) + " | ");printLinkedList(head);System.out.println("=========================");head = new Node(1);head.next = new Node(2);head.next.next = new Node(3);head.next.next.next = new Node(1);printLinkedList(head);System.out.print(isPalindrome1(head) + " | ");System.out.print(isPalindrome2(head) + " | ");System.out.println(isPalindrome3(head) + " | ");printLinkedList(head);System.out.println("=========================");head = new Node(1);head.next = new Node(2);head.next.next = new Node(2);head.next.next.next = new Node(1);printLinkedList(head);System.out.print(isPalindrome1(head) + " | ");System.out.print(isPalindrome2(head) + " | ");System.out.println(isPalindrome3(head) + " | ");printLinkedList(head);System.out.println("=========================");head = new Node(1);head.next = new Node(2);head.next.next = new Node(3);head.next.next.next = new Node(2);head.next.next.next.next = new Node(1);printLinkedList(head);System.out.print(isPalindrome1(head) + " | ");System.out.print(isPalindrome2(head) + " | ");System.out.println(isPalindrome3(head) + " | ");printLinkedList(head);System.out.println("=========================");}}

将单链表按照给定的数值,划分成左边小、中间相等、右边大的形式 (荷兰国旗)

思路 方法一

  • 1,申请一个链表长度大小一致的数组,然后遍历链表的过程中,将每一个点放到数组容器中,在数组里面进行荷兰国旗问题,再把数组容器中的元素都串联起来,形成一个链表返回
  • 第一种方法使用的排序 方式思路以及代码如下:
  • 设置 small 从左边开始移动,只要small对应位置的元素的数值小于pivot(用户输入的数值),small就进行移动,同时移动index,使small和index同时向后移动;注意++small index-- ;和初始赋值有关系
  • big从右边开始移动;只有index对应位置上的元素的数值 大于 用户输入的数值,就需要交换 index上的数值  和  big指向的数值;将大的数移动到右边,--big,index不要动,接下来检查index的数值
  • 如果index 指向的数值  和  用户输入的数值相等,只需要移动index
    public static void arrPartition(Node[] nodeArr,int pivot){int small = -1;int big = nodeArr.length;int index = 0;while (index != big){if (nodeArr[index].value < pivot){swap(nodeArr,++small,index++);} else if (nodeArr[index].value == pivot){++index;} else{swap(nodeArr,--big,index);}}}

思路 方法二

  • 2,保证稳定性:根据题目要求设置三个区,小于区、等于区和大于区,每个区间包含两个变量,开始节点和结尾节点,一共设置6个变量,6个变量都指向null;当遇到第一个元素3的时候,它是小于指定元素5的,将小于区域的开始和结束指针都指向3;第二个元素是5,属于等于区,让等于区的start和end都指向第二个元素5;第3个元素也是5,让等于区的end只想第三个元素。以此类推,得到上面的结果。最后将小于区域的end指针链接等于区域的start指针,等于区域的end指针链接大于区域的start指针。
  • 需要注意的是,有可能上面6个变量有不存在的情形,需要仔细判别。
  • 链表天然具有稳定性  保持元素的前后位置的一致性;相较于方法一,避免了数据的交换

package com.example.algorithm.demo.class04;import org.w3c.dom.Node;public class Code05_SmallerEqualBigger {public static class Node {public int value;public Node next;public Node(int data){this.value = data;}}public static void swap(Node[] nodeArr,int a,int b){Node tmp = nodeArr[a];nodeArr[a] = nodeArr[b];nodeArr[b] = tmp;}public static void arrPartition(Node[] nodeArr,int pivot){int small = -1;int big = nodeArr.length;int index = 0;while (index != big){if (nodeArr[index].value < pivot){swap(nodeArr,++small,index++);} else if (nodeArr[index].value == pivot){++index;} else{swap(nodeArr,--big,index);}}}public static Node listPartition1(Node head,int pivot){if (head == null){return head;}Node cur = head;int i = 0;while (cur != null){i++;cur = cur.next;}Node[] nodeArr = new Node[i];i = 0;cur = head;for (i = 0; i != nodeArr.length;i++){nodeArr[i] = cur;cur = cur.next;}arrPartition(nodeArr,pivot);for (i = 1;i != nodeArr.length;i++){nodeArr[i-1].next = nodeArr[i];}nodeArr[i-1].next = null;return nodeArr[0];}public static Node listPartition2(Node head,int pivot){Node sH = null;Node sT = null;Node eH = null;Node eT = null;Node bH = null;Node bT = null;Node next = null;while (head != null){next = head.next;head.next = null;if (head.value < pivot){if (sH == null){sH = head;sT = head;} else {sT.next = head;sT = head;}} else if(head.value == pivot){if (eH == null){eH = head;eT = head;} else {eT.next = head;eT = head;}} else {if (bH == null){bH = head;bT = head;} else {bT.next = head;bT = head;}}}head = next;if (sT != null){sT.next = eH;eT = eT == null ? sT : eT;}if (eT != null){eT.next = bH;}return sH != null ? sH : eH != null ? eH : bH;}public static void printLinkedList(Node node) {System.out.print("Linked List: ");while (node != null) {System.out.print(node.value + " ");node = node.next;}System.out.println();}public static void main(String[] args) {Node head1 = new Node(7);head1.next = new Node(9);head1.next.next = new Node(1);head1.next.next.next = new Node(8);head1.next.next.next.next = new Node(5);head1.next.next.next.next.next = new Node(2);head1.next.next.next.next.next.next = new Node(5);printLinkedList(head1);head1 = listPartition1(head1, 4);
//        head1 = listPartition2(head1, 5);printLinkedList(head1);}
}

复制含有随机指针节点的链表

  • 【题目】一种特殊的单链表节点类描述如下

    public static class Node{public int value;public Node next;public Node rand;public Node(int data){this.value = data;}}
  • rand指针是单链表节点结构中新增的指针,rand可能指向链表中的任意一个节点,也可能指向null。
  • 给定一个由Node节点类型组成的无环单链表的头节点 head,请实现一个函数完成这个链表的复制,并返回复制的新链表的头节点。
  • 【要求】时间复杂度O(N),额外空间复杂度O(1)
  • 方法1 利用map,key和value都是Node类型;使用新建的类型为Node的Value节点存储节点的下一个和随机指针,然后抛弃先前的链表,使用map存储的记录实现链表的拼接;map.get(cur).next = map.get(cur.next);
    map.get(cur).rand = map.get(cur.rand);分别指定节点的下一个和随机指针
  • 方法2 遍历链表,在每个节点的后面创建对应的副本;然后将每一个新建的节点进行串联,形成拷贝;
        //创建节点 填入元素Node cur = head;Node next = null;while (cur != null){next = cur.next;  //指向新创建的节点的下一个cur.next = new Node(cur.value);  //新建节点cur.next.next = next;  //衔接新创建的节点和先前节点,相当于在指定位置插入节点cur = next;  //指向旧的节点}//分离节点Node res = head.next;cur = head;while (cur != null){next = cur.next.next;curCopy = cur.next;cur.next = next;curCopy.next = next != null ? next.next : null;cur = next;}
Codepackage class04;import java.util.HashMap;public class Code06_CopyListWithRandom {public static class Node {public int value;public Node next;public Node rand;public Node(int data) {this.value = data;}}public static Node copyListWithRand1(Node head) {HashMap<Node, Node> map = new HashMap<Node, Node>();Node cur = head;while (cur != null) {map.put(cur, new Node(cur.value));cur = cur.next;}cur = head;while (cur != null) {map.get(cur).next = map.get(cur.next);map.get(cur).rand = map.get(cur.rand);cur = cur.next;}return map.get(head);}public static Node copyListWithRand2(Node head) {if (head == null) {return null;}Node cur = head;Node next = null;// copy node and link to every nodewhile (cur != null) {next = cur.next;cur.next = new Node(cur.value);cur.next.next = next;cur = next;}cur = head;Node curCopy = null;// set copy node randwhile (cur != null) {next = cur.next.next;curCopy = cur.next;curCopy.rand = cur.rand != null ? cur.rand.next : null;cur = next;}Node res = head.next;cur = head;// splitwhile (cur != null) {next = cur.next.next;curCopy = cur.next;cur.next = next;curCopy.next = next != null ? next.next : null;cur = next;}return res;}public static void printRandLinkedList(Node head) {Node cur = head;System.out.print("order: ");while (cur != null) {System.out.print(cur.value + " ");cur = cur.next;}System.out.println();cur = head;System.out.print("rand:  ");while (cur != null) {System.out.print(cur.rand == null ? "- " : cur.rand.value + " ");cur = cur.next;}System.out.println();}public static void main(String[] args) {Node head = null;Node res1 = null;Node res2 = null;printRandLinkedList(head);res1 = copyListWithRand1(head);printRandLinkedList(res1);res2 = copyListWithRand2(head);printRandLinkedList(res2);printRandLinkedList(head);System.out.println("=========================");head = new Node(1);head.next = new Node(2);head.next.next = new Node(3);head.next.next.next = new Node(4);head.next.next.next.next = new Node(5);head.next.next.next.next.next = new Node(6);head.rand = head.next.next.next.next.next; // 1 -> 6head.next.rand = head.next.next.next.next.next; // 2 -> 6head.next.next.rand = head.next.next.next.next; // 3 -> 5head.next.next.next.rand = head.next.next; // 4 -> 3head.next.next.next.next.rand = null; // 5 -> nullhead.next.next.next.next.next.rand = head.next.next.next; // 6 -> 4printRandLinkedList(head);res1 = copyListWithRand1(head);printRandLinkedList(res1);res2 = copyListWithRand2(head);printRandLinkedList(res2);printRandLinkedList(head);System.out.println("=========================");}}

两个单链表相交的一系列问题

  • 【题目】给定两个可能有环也可能无环的单链表,头节点head1和head2。请实现一个函数,如果两个链表相交,请返回相交的 第一个节点。如果不相交,返 回null
  • 【要求】如果两个链表长度之和为N,时间复杂度请达到O(N),额外空间复杂度 请达到O(1)。
  • 两个单链表相交的一系列问题
  • 相交:共用内存地址
  • 注意事项:每个节点只有next指针,不可以有两个指出的指针
  • 有环/无环:写一个函数,输入的类型是链表的头节点,判断是否有环,以及返回第一个入环的节点。
  • 方法一:使用集合来做,遍历链表,每遍历一个元素,将其放入到集合中,判定是否存在此元素,如果将一个元素放入集合中,发现他已经存在,则是有环的,并且他就是第一个入环节点。
  • 方法二:使用快慢指针来做,快指针每次移动俩个位置,慢指针每次移动一个位置,当快慢指针第一次相交之后,快指针回到链表的起始点,慢指针呆在原地不动。然后快指针和慢指针都每次移动一个位置,当他们再次相遇之后,相遇的元素就是入环的第一个元素,且能证明这个链表是有环的结构。上图所示的是环外4个点,环内4个点,可以按照这个流程走一遍。
  • 使用函数(返回第一个入环的节点)如果返回的是null 说明链表无环;如果两个链表都无环,找到两个链表最后的位置,如果最后的位置相等 ,说明链表相交;否则链表不想交;两个无环链表相交问题,哪个链表长,先走比短链表多余的部分,然后一起走,只要有一点的内存地址相稳合,则代表两者相交。

  • 如果一个是有环的,一个是无环的,那么他俩一定不相交  不可以出现两个指出的指针

  • 两个都有环的 链表 ,可以出现三种情况
  • 第一种情形,使用其中一个入环节点绕着环走一圈,如果可以找到另外的入环节点就是第三种情形;否则就是第一种情形
  • 第二种情形,将第一个入环节点作为判断终止的条件

package class04;public class Code07_FindFirstIntersectNode {public static class Node {public int value;public Node next;public Node(int data) {this.value = data;}}public static Node getIntersectNode(Node head1, Node head2) {if (head1 == null || head2 == null) {return null;}Node loop1 = getLoopNode(head1);Node loop2 = getLoopNode(head2);if (loop1 == null && loop2 == null) {return noLoop(head1, head2);}if (loop1 != null && loop2 != null) {return bothLoop(head1, loop1, head2, loop2);}return null;}public static Node getLoopNode(Node head) {if (head == null || head.next == null || head.next.next == null) {return null;}Node n1 = head.next; // n1 -> slowNode n2 = head.next.next; // n2 -> fastwhile (n1 != n2) {if (n2.next == null || n2.next.next == null) {return null;}n2 = n2.next.next;n1 = n1.next;}n2 = head; // n2 -> walk again from headwhile (n1 != n2) {n1 = n1.next;n2 = n2.next;}return n1;}public static Node noLoop(Node head1, Node head2) {if (head1 == null || head2 == null) {return null;}Node cur1 = head1;Node cur2 = head2;int n = 0;while (cur1.next != null) {n++;cur1 = cur1.next;}while (cur2.next != null) {n--;cur2 = cur2.next;}if (cur1 != cur2) {return null;}cur1 = n > 0 ? head1 : head2;cur2 = cur1 == head1 ? head2 : head1;n = Math.abs(n);while (n != 0) {n--;cur1 = cur1.next;}while (cur1 != cur2) {cur1 = cur1.next;cur2 = cur2.next;}return cur1;}public static Node bothLoop(Node head1, Node loop1, Node head2, Node loop2) {Node cur1 = null;Node cur2 = null;if (loop1 == loop2) {cur1 = head1;cur2 = head2;int n = 0;while (cur1 != loop1) {n++;cur1 = cur1.next;}while (cur2 != loop2) {n--;cur2 = cur2.next;}cur1 = n > 0 ? head1 : head2;cur2 = cur1 == head1 ? head2 : head1;n = Math.abs(n);while (n != 0) {n--;cur1 = cur1.next;}while (cur1 != cur2) {cur1 = cur1.next;cur2 = cur2.next;}return cur1;} else {cur1 = loop1.next;while (cur1 != loop1) {if (cur1 == loop2) {return loop1;}cur1 = cur1.next;}return null;}}public static void main(String[] args) {// 1->2->3->4->5->6->7->nullNode head1 = new Node(1);head1.next = new Node(2);head1.next.next = new Node(3);head1.next.next.next = new Node(4);head1.next.next.next.next = new Node(5);head1.next.next.next.next.next = new Node(6);head1.next.next.next.next.next.next = new Node(7);// 0->9->8->6->7->nullNode head2 = new Node(0);head2.next = new Node(9);head2.next.next = new Node(8);head2.next.next.next = head1.next.next.next.next.next; // 8->6System.out.println(getIntersectNode(head1, head2).value);// 1->2->3->4->5->6->7->4...head1 = new Node(1);head1.next = new Node(2);head1.next.next = new Node(3);head1.next.next.next = new Node(4);head1.next.next.next.next = new Node(5);head1.next.next.next.next.next = new Node(6);head1.next.next.next.next.next.next = new Node(7);head1.next.next.next.next.next.next = head1.next.next.next; // 7->4// 0->9->8->2...head2 = new Node(0);head2.next = new Node(9);head2.next.next = new Node(8);head2.next.next.next = head1.next; // 8->2System.out.println(getIntersectNode(head1, head2).value);// 0->9->8->6->4->5->6..head2 = new Node(0);head2.next = new Node(9);head2.next.next = new Node(8);head2.next.next.next = head1.next.next.next.next.next; // 8->6System.out.println(getIntersectNode(head1, head2).value);}}

牛客网 链表结构 算法相关内容相关推荐

  1. 牛客网在线编程----算法入门篇

    标题本篇博文主要是记录下自己的在线编程情况,初次练习,有的算法还待改进,大家有需要可以去牛客网上面多练练! 有需戳–>牛客网在线编程 NC65.题目描述 大家都知道斐波那契数列,现在要求输入一个 ...

  2. 一口气刷完牛客网全部机器学习算法题

    不知道为什么最近突然觉得牛客网很火,好奇心驱使下我也点开看了看...发现真的不错. 机器学习是python新增加的板块,其实只有5道题 哈哈 . ps:题目很简单很基础,真的很适合刚刚入门机器学习的小 ...

  3. 【Java】牛客网 链表分割

    题目描述 : 现有一链表的头指针 ListNode* pHead,给一定值x,编写一段代码将所有小于x的结点排在其余结点之前,且不能改变原来的数据顺序,返回重新排列后的链表的头指针. 解题思路 : 假 ...

  4. 牛客网力扣算法编程之十四 | 字符串 - 字符个数统计 - Java代码实现

    [算法编程]字符个数统计 一. 题目描述 编写一个函数,计算字符串中含有的不同字符的个数.字符在 ASCII 码范围内( 0~127 ,包括 0 和 127 ),换行表示结束符,不算在字符里.不在范围 ...

  5. 牛客网 - 链表相加

    问题: 解题思路: 可以把节点数据提取出来存在列表里然后去算,当然,喜提时间爆表 还是老老实实在走节点的过程中就加然后建立链表 注意进位的设置,卡我十分钟的点在于q = self.reverse(q) ...

  6. 华为机试python编程题_牛客网华为机试题之Python解法

    牛客网华为机试题之Python解法 第1题 字符串最后一个单词的长度 a = input().split(" ") print(len(a[-1])) 第2题 计算字符个数 a = ...

  7. 牛客网刷算法题的输入输出(C++)

    内容简述 该篇文章将对牛客网刷题中关于输入输出的一些问题作一个总结.每年互联网公司的招聘都必不可少会有算法题,因此平时很多人都会去一些刷题网站进行刷题来学习.这里面用的比较多的刷题网站是leetcod ...

  8. 牛客网《BAT面试算法精品课》学习笔记

    目录 牛客网<BAT面试算法精品课>学习笔记 牛客网<BAT面试算法精品课>笔记一:排序 牛客网<BAT面试算法精品课>笔记二:字符串 牛客网<BAT面试算法 ...

  9. 牛客网算法工程师能力评估

    牛客网算法工程师能力评估 题目来源:https://www.nowcoder.com/test/200/summary 1.递归算法x(x(8))需要调用几次函数x(int n)? class pro ...

最新文章

  1. 阿里数学竞赛最年轻金奖得主:15岁读少年班,21岁UC伯克利读博,想毕业就回国...
  2. 机器学习笔记:时间序列分解(滑动平均)
  3. 错误 C2664 “int WideCharToMultiByte......”: 无法将参数 3 从“CString”转换为“LPCWCH” 的问题解决
  4. Light OJ 1214 Large Division (大数取模)
  5. codevs2171 棋盘覆盖
  6. 2021 测试工作年终总结
  7. 使用shadow dom封装web组件
  8. 虚拟机(VMWARE)安装的系统如何访问本地磁盘
  9. 计算机管理器磁盘清理,win10 磁盘空间清理管理器已停止工作怎么解决
  10. 卡方分布上侧α分位数的近似公式及其证明
  11. 利用浏览器缓存抓取网络资源:【炉石传说】所有卡牌png图片地址
  12. 单精度与双精度是什么意思,有什么区别?
  13. Linux基础-2、基本命令
  14. 记录第一次纯手打爬虫经历
  15. 今个大言不惭下,讲一讲嘛是文化属性,有啥用?
  16. 智能语音电话机器人系统源码
  17. 2.2总线的性能指标
  18. DPDK 分析,原理以及学习路线
  19. 推荐一个很好用的在线文档翻译器:翻译狗
  20. 英文文献 安全 计算机,文献综述-中英文文献翻译-计算机数控机床的安全和维护...

热门文章

  1. python中execute函数_Python中的函数定义与参数使用
  2. 广义典型相关分析_重复测量数据分析及结果详解(之二)——广义估计方程
  3. 【转】三、QT例子-打开一个图片并且显示
  4. 【转】人工智能-1.1.1 什么是神经网络
  5. ASP.Net请求处理机制初步探索之旅 - Part 3 管道
  6. [你必须知道的.NET]第十七回:貌合神离:覆写和重载
  7. oracle 建分区索引_Oracle分区表及分区索引-创建list分区
  8. Python 数据分析三剑客之 NumPy(六):矩阵 / 线性代数库与 IO 操作
  9. 【2018ACM山东省赛 - B】Bullet(二分 + 二分图匹配,匈牙利算法,卡常)
  10. 【7-10 PAT】树的遍历(给定一棵二叉树的后序遍历和中序遍历,请你输出其层序遍历的序列。)