数组
摘要:1 寻找数组的中心索引 class Solution { public int pivotIndex(int[] nums) { if(nums.length==1){return 0;} if(nums.length==0){return -1;} int left=0; for(int i=0;
阅读全文
java 遍历数组
摘要:1 只遍历一遍数组 public class ThroughTheArray{ public static void main(String[] args) { int[] arr = {12,4,1,66,54,6,74,-3}; for (int i = 0; i < arr.length; i
阅读全文
字符串
摘要:1 最长公共前缀 class Solution { public String longestCommonPrefix(String[] strs) { if (strs==null || strs.length==0) return ""; int length = strs[0].length(
阅读全文
排序
摘要:冒泡排序法 public static void main(String[] args) { int arr[] = {8, 5, 3, 2, 4}; //冒泡 for (int i = 0; i < arr.length; i++) { //外层循环,遍历次数 for (int j = 0; j
阅读全文
树
摘要:(1)前序遍历:前序遍历首先访问根节点,然后遍历左子树,最后遍历右子树 (2)中序遍历:中序遍历是先遍历左子树,然后访问根节点,然后遍历右子树 (3)后序遍历:后序遍历是先遍历左子树,然后遍历右子树,最后访问树的根节点。 二 树的存储结构 public class TreeNode { int va
阅读全文