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

小精灵儿童网站免费做踢企业推广

小精灵儿童网站免费做踢,企业推广,jsp 网站连接数据库,长春盛网网站建设今天回顾一下下面三个算法#xff0c;涉及到了动态规划、合并链表、位运算#xff0c;好吧#xff0c;让我们再次手敲一遍 //乘积最大子数组//思路: 维护三个变量#xff0c;imax最大前缀乘积 imin最小前缀乘积 max最大连续乘积//由于元素有正负#xff0c;imax和imin需…今天回顾一下下面三个算法涉及到了动态规划、合并链表、位运算好吧让我们再次手敲一遍 //乘积最大子数组//思路: 维护三个变量imax最大前缀乘积 imin最小前缀乘积 max最大连续乘积//由于元素有正负imax和imin需要互换所以需要单独维护一个max用于记录最大连续乘积public int maxProduct(int[] nums) {if (nums null || nums.length 0) {return -1;}if (nums.length 1) {return nums[0];}int imax 1, imin 1, max Integer.MIN_VALUE;for (int i 0; i nums.length; i) {if (nums[i] 0) {int temp imax;imax imin;imin temp;}imax Math.max(nums[i], imax * nums[i]);imin Math.min(nums[i], imin * nums[i]);max Math.max(max, imax);}return max;}//排序链表//思路: 先将链表分成多条长度为1length的子链表然后合并两条长度为1的有序子链表//接着把链表分为多条长度为2length的子链表然后合并两条长度为2的有序子链表//重复以上步骤直到length大于等于链表的长度结束public ListNode sortList(ListNode head) {if (head null) {return null;}int length 0;ListNode curr head;while (curr ! null) {length;curr curr.next;}ListNode dummyHead new ListNode(0, head);for (int subLength 1; subLength length; subLength subLength * 2) {ListNode prev dummyHead;curr dummyHead.next;while (curr ! null) {ListNode head1 curr, head2;for (int i 1; i subLength curr ! null curr.next ! null; i) {curr curr.next;}head2 curr.next;curr.next null;curr head2;for (int i 1; i subLength curr ! null curr.next ! null; i) {curr curr.next;}ListNode dailyListHead null;if (curr ! null) {dailyListHead curr.next;curr.next null;}prev.next merged(head1, head2);while (prev.next ! null) {prev prev.next;}curr dailyListHead;}}return dummyHead.next;}private ListNode merged(ListNode head1, ListNode head2) {ListNode dummyHead new ListNode(0);ListNode temp dummyHead, temp1 head1, temp2 head2;while (temp1 ! null temp2 ! null) {if (temp1.val temp2.val) {temp.next temp2;temp2 temp2.next;} else {temp.next temp1;temp1 temp1.next;}temp temp.next;}if (temp1 ! null) {temp.next temp1;} else if (temp2 ! null) {temp.next temp2;}return dummyHead.next;}//只出现一次的数字//思路: 利用异或运算进行求解异或运算性质0异或任何数都等于本身任何数与本身异或都等于0public int singleNumber(int[] nums) {int single 0;for (int i 0; i nums.length; i) {single ^ nums[i];}return single;}
http://www.w-s-a.com/news/564407/

相关文章:

  • 健身俱乐部网站开发文档建一个网站需要什么条件
  • 买的网站模板怎么做建设行政管理部门网站
  • 怎么让百度多收录网站关键词seo深圳
  • 陕西交通建设集团网站体检个人网站设计模板田田田田田田田田
  • ae模板网站推荐安徽建筑信息平台
  • 新网站建设代理商wordpress模板商店
  • 中国十大设计素材网站wordpress发布失败
  • 江西省建设监理网站网页制作与设计是什么
  • 在招聘网站做销售怎么样网址你懂我意思正能量不用下载ios
  • 高端企业网站定制公司企业网站2000元
  • 成都网站建设:河北省建设工程质量监督网站
  • 四川省建设厅官网信息查询平台北京seo关键词优化外包
  • 网站建设响应式是什么意思wordpress弹窗打开网页
  • 做美工需要参考的网站漳州做网站的公司
  • 用源码建设网站关于网站开发的自我评价
  • 网站设计师图片自助建站编辑器
  • 网站建设的常用技术有哪些深圳建筑工地招工
  • 做软装找图片的网站wordpress 替代
  • 制作网站的后台公众号做视频网站会封吗
  • 广西企业建站邯郸景区网站制作
  • 开发商城网站多少钱城厢区建设局网站
  • 网站外链多的危害天水市建设局网站
  • 网站接入商学交互设计网站
  • 目前最新的网站后台架构技术综述什么网站可以做名片
  • 成都建站长沙做网站美工的公司
  • 湖南省住房与城乡建设厅网站平顶山网站关键词优化
  • 购物网站前台功能模块汕头网站设计电话
  • 网站你懂我意思正能量免费wordpress菜单底部导航代码
  • 一个主机可以建设多少个网站山东高端网站建设
  • 长沙网站建设搭建网络营销做得好的公司