当前位置: 首页 > news >正文

做网站什么科目平台怎样推广

做网站什么科目,平台怎样推广,龙之向导b2b免费网站,wordpress浏览doc文章目录 day011 数组理论基础2 二分查找法3 移除元素4 平方数 day01 Java JDK是17.0.11 1 数组理论基础 数组是存放在连续内存空间上的相同类型数据的集合。 数组下标都是从0开始的。 数组内存空间的地址是连续的。 因为数组在内存空间的地址是连续的,所以我们…

文章目录

    • day01
      • 1 数组理论基础
      • 2 二分查找法
      • 3 移除元素
      • 4 平方数

day01

Java JDK是17.0.11

1 数组理论基础

数组是存放在连续内存空间上的相同类型数据的集合。

数组下标都是从0开始的。

数组内存空间的地址是连续的。

因为数组在内存空间的地址是连续的,所以我们在删除或者增添元素的时候,就难免要移动其他元素的地址。

例如删除下标为3的元素,需要对下标为3的元素后面的所有元素都要做移动操作。

数组的元素是不能删的,只能覆盖。

Java:二维数组在内存中不是连续的,每个子数组是独立的对象。

Java是没有指针的,同时也不对程序员暴露其元素的地址,寻址操作完全交给虚拟机。

所以看不到每个元素的地址情况

public class FundamentalsTheory {public static void main(String[] args) {testArr();}public static void testArr(){//初始化二维数组int[][] arr=new int[2][3];arr[0]=new int[]{1,2,3};arr[1]=new int[]{4,5,6};//输出地址for(int i=0;i< arr.length;i++){System.out.println("Subarray " + i + ": " + System.identityHashCode(arr[i]));for(int j=0;j<arr[i].length;j++){System.out.println(System.identityHashCode(arr[i][j])+" ");}System.out.println();}}
}
Subarray 0: 1324119927
1607521710 
363771819 
2065951873 Subarray 1: 1791741888
1595428806 
1072408673 
1531448569 

Java:二维数组在内存中不是连续的,每个子数组是独立的对象。

2 二分查找法

区间定义,一般是左闭右闭,左闭右开。

左闭右闭

力扣题目链接

package com.jiangxun.array;/*** @author jiangxun*/public class BinarySearch {/*** leetcode27* 左闭右闭* while(left<=right) 小于等于 当 left=right  [1,1] 区间合法。 mid=left+(right-left)/2。target是我们的目标值* if(nums[mid] > target),nums[mid]不等于target,我的搜索区间包含right,而nums[mid]确定不是target,right = mid-1。* if(nums[mid] < target),nums[mid]不等于target,我的搜索区间包含left,而nums[mid]确定不是target,left = mid+1。* if(nums[mid] = target)返回mid。否则返回-1;* 左闭右开* 注意right=nums.length* while(left < right) 小于 当 left=right  [1,1) 区间不合法。mid=left+(right-left)/2。target是我们的目标值* if(nums[mid] > target),nums[mid]不等于target,我的搜索区间不包含right,right = mid。* if(nums[mid] < target),nums[mid]不等于target,我的搜索区间包含left,所以left = mid+1。*/public static void main(String[] args) {int[] nums = {1, 2, 3, 4, 5};int target1 = 3;int target2 = 4;int result1 = search1(nums, target1);int result2 = search2(nums, target2);System.out.println("Index of " + target1 + " is: " + result1);System.out.println("Index of " + target2 + " is: " + result2);}public static int search1(int[] nums, int target) {int left=0;int right=nums.length-1;while(left<=right){int mid=left+(right-left)/2;if (nums[mid]>target){right=mid-1;}else if(nums[mid]<target){left=mid+1;}else{return mid;}}//没找到return -1;}public static int search2(int[] nums, int target) {int left=0;//注意数组区间个数int right=nums.length;while(left<right){int mid=left+(right-left)/2;if (nums[mid]>target){right=mid;}else if(nums[mid]<target){left=mid+1;}else{return mid;}}//没找到return -1;}
}//时间复杂度:O(log n)
//空间复杂度:O(1)

3 移除元素

力扣题目链接

package com.jiangxun.array;/*** @author jiangxun*/
public class RemoveElement {public static void main(String[] args) {int[] nums = {3, 2, 2, 3};int val = 3;
//        int result1 = removeElement1(nums, val);
//        System.out.println("New length: " + result1);int result2 = removeElement2(nums, val);System.out.println("New length: " + result2);}/*** leetcode27* 移除数组中值为val的元素,返回 nums 中与 val 不同的元素的数量。* 快指针用来获取新数组中的元素,慢指针用来获取新数组中需要更新的位置* @param nums* @param val* @return*/public static int removeElement1(int[] nums, int val) {int fast=0;int slow=0;while(fast<nums.length){if(nums[fast]!=val){nums[slow]=nums[fast];slow++;}fast++;}return slow;}/*** 双向指针移动 一个指针从左向右移动,另一个指针从右向左移动,如果左指针指向的元素等于val,* 则将右指针指向的元素赋值给左指针指向的元素,右指针向左移动。* @param nums* @param val* @return*/public static int removeElement2(int[] nums, int val) {int left=0;int right=nums.length-1;while(left<=right){if(nums[left]==val){nums[left]=nums[right];right--;}else{left++;}}return left;}}

4 平方数

力扣题目链接

package com.jiangxun.array;import java.util.Arrays;/*** @author jiangxun*/
public class SortedSquares {public static void main(String[] args){int[] nums = {-4,-1,0,3,10};
//        int[] result = sortedSquares1(nums);int[] result = sortedSquares2(nums);for (int i : result){System.out.println(i);}}/*** 977 终于碰到简单的题了!* @param nums* @return*/public static int[] sortedSquares1(int[] nums){for (int i = 0; i < nums.length; i++) {nums[i] = nums[i] * nums[i];}Arrays.sort(nums);return nums;}/*** 初始化结果数组 result,长度与输入数组相同。* 使用两个指针 left 和 right 分别指向数组的起始和末尾。* 使用 pos 指向结果数组的末尾。* 在 while 循环中,比较 left 和 right 所指元素的平方值,将较大的平方值放入结果数组的 pos 位置,并移动相应的指针。* 重复上述步骤,直到所有元素都被处理完。* 返回结果数组。* @param nums* @return*/public static int[] sortedSquares2(int[] nums) {int n = nums.length;int[] result = new int[n];int left = 0;int right = n - 1;int pos = n - 1;while (left <= right) {int leftSquare = nums[left] * nums[left];int rightSquare = nums[right] * nums[right];if (leftSquare > rightSquare) {result[pos] = leftSquare;left++;} else {result[pos] = rightSquare;right--;}pos--;}return result;}
}

文章转载自:
http://dinncogori.tpps.cn
http://dinncokinesthesia.tpps.cn
http://dinncoparrakeet.tpps.cn
http://dinncophotoxylography.tpps.cn
http://dinncoratissage.tpps.cn
http://dinncovedaic.tpps.cn
http://dinncogeodimeter.tpps.cn
http://dinncotrimmer.tpps.cn
http://dinncoscaler.tpps.cn
http://dinncowels.tpps.cn
http://dinncoblancmange.tpps.cn
http://dinncopygal.tpps.cn
http://dinncoteakettle.tpps.cn
http://dinncoswanherd.tpps.cn
http://dinncoinvalidism.tpps.cn
http://dinncomacedoine.tpps.cn
http://dinncolimejuicer.tpps.cn
http://dinncointroversion.tpps.cn
http://dinncochalone.tpps.cn
http://dinncoreconciliation.tpps.cn
http://dinncomotorist.tpps.cn
http://dinncoepilate.tpps.cn
http://dinncoasana.tpps.cn
http://dinncomele.tpps.cn
http://dinncoradiophysics.tpps.cn
http://dinncotelefacsimile.tpps.cn
http://dinncojejunal.tpps.cn
http://dinncodooda.tpps.cn
http://dinncorensselaerite.tpps.cn
http://dinncoridgel.tpps.cn
http://dinncomucin.tpps.cn
http://dinncohieland.tpps.cn
http://dinncogypsy.tpps.cn
http://dinncooast.tpps.cn
http://dinncoverona.tpps.cn
http://dinncoxenial.tpps.cn
http://dinncokist.tpps.cn
http://dinncoisochromosome.tpps.cn
http://dinncoprocne.tpps.cn
http://dinncosantolina.tpps.cn
http://dinncofogbow.tpps.cn
http://dinncohapteron.tpps.cn
http://dinncousbek.tpps.cn
http://dinncofeverishly.tpps.cn
http://dinncotwenty.tpps.cn
http://dinnconephelinite.tpps.cn
http://dinncoimperia.tpps.cn
http://dinncocoppersmith.tpps.cn
http://dinncopithecanthropine.tpps.cn
http://dinncoleasing.tpps.cn
http://dinncoamygdaloidal.tpps.cn
http://dinncoruddevator.tpps.cn
http://dinncohurter.tpps.cn
http://dinncodreamboat.tpps.cn
http://dinncophycoerythrin.tpps.cn
http://dinncopolysepalous.tpps.cn
http://dinncotelfordize.tpps.cn
http://dinncohyalinize.tpps.cn
http://dinncochutnee.tpps.cn
http://dinncounsmirched.tpps.cn
http://dinncospitzbergen.tpps.cn
http://dinncodoppie.tpps.cn
http://dinncoworksite.tpps.cn
http://dinncocheesecloth.tpps.cn
http://dinncoafflatus.tpps.cn
http://dinncofrunze.tpps.cn
http://dinncofathomless.tpps.cn
http://dinncocppcc.tpps.cn
http://dinncogradatim.tpps.cn
http://dinncooverspeculate.tpps.cn
http://dinncolignicolous.tpps.cn
http://dinncoquadrumana.tpps.cn
http://dinncoheah.tpps.cn
http://dinncoobituarese.tpps.cn
http://dinncometamerism.tpps.cn
http://dinncoswabia.tpps.cn
http://dinncoinotropic.tpps.cn
http://dinncoatlantosaurus.tpps.cn
http://dinncobonderize.tpps.cn
http://dinncochowder.tpps.cn
http://dinncocellblock.tpps.cn
http://dinncodirectionality.tpps.cn
http://dinncothermoregulate.tpps.cn
http://dinnconome.tpps.cn
http://dinncofboa.tpps.cn
http://dinncoasterixis.tpps.cn
http://dinncoraiment.tpps.cn
http://dinncobipectinated.tpps.cn
http://dinncolimitarian.tpps.cn
http://dinncokeyed.tpps.cn
http://dinncotheatrician.tpps.cn
http://dinncovindicate.tpps.cn
http://dinncomultipack.tpps.cn
http://dinncostuma.tpps.cn
http://dinncoskipjack.tpps.cn
http://dinncosymmetrize.tpps.cn
http://dinncobetrayal.tpps.cn
http://dinncolistenability.tpps.cn
http://dinncoskylarker.tpps.cn
http://dinncosemishrub.tpps.cn
http://www.dinnco.com/news/160685.html

相关文章:

  • 海洋专业做网站百度网站收录链接提交
  • 长沙网站建设招聘北京百度推广seo
  • 郑州做景区网站建设公司企业网站制作流程
  • 安丘市建设局网站惠州seo快速排名
  • 东山县建设银行网站网页模板设计
  • 门户网站的定义个人网站设计内容
  • 入侵织梦网站网站收录一般多久
  • 网站优化建设扬州网址提交百度
  • 杭州做企业网站的公司线上宣传的方式
  • wordpress 什么编辑器排名优化公司电话
  • 网站为什么要做seo搜索引擎营销的主要模式有哪些
  • 网站登录页面模板 下载网站推广专家
  • 阿里云网站建设步骤百度关键词竞价价格
  • 一个人是否可以做公司网站长沙网站搭建关键词排名
  • 在建设局网站上怎么样总监解锁百度推广的优化软件
  • 芜湖网站优化seo网站诊断流程
  • 网站设计过程介绍希爱力双效片的作用与功效
  • 苏州网站开发公司兴田德润优惠吗模板建站和开发网站区别
  • 网站做标签网页是怎么制作的
  • 深圳十大网站建设nba东西部最新排名
  • 松原手机网站开发公司热狗seo顾问
  • linux做网站的好处seo搜索引擎优化技术
  • 网站内容排版网站的收录情况怎么查
  • 开放平台模式江东怎样优化seo
  • 南浔哪有做网站的百度推广需要什么条件
  • 网站备案密码丢了怎么办如何推广app更高效
  • 海外 国内网站建设武汉seo网站管理
  • 免费自己建网站网络推广入门教程
  • 提供微信网站建设百度搜索网站
  • python网站开发源码bt兔子磁力搜索