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

网站内容策划方案wordpress本地路径

网站内容策划方案,wordpress本地路径,青县有做网站的吗,网站设计目的目录 1、两数之和2、移动零3、相交链表4、有效的括号5、反转链表6、回文链表7、环形链表8、环形链表II9、合并两个有序链表10、二叉树的中序遍历 1、两数之和 1. 两数之和 - 力扣(LeetCode) 方法1: class Solution {public int[] twoSum(i…

目录

  • 1、两数之和
  • 2、移动零
  • 3、相交链表
  • 4、有效的括号
  • 5、反转链表
  • 6、回文链表
  • 7、环形链表
  • 8、环形链表II
  • 9、合并两个有序链表
  • 10、二叉树的中序遍历

1、两数之和

1. 两数之和 - 力扣(LeetCode)在这里插入图片描述

方法1:

class Solution {public int[] twoSum(int[] nums, int target) {int[] ret = new int[2];for(int i=0;i<nums.length;i++){for(int j=i+1;j<nums.length;j++) {if(nums[i]+nums[j]==target) {ret[0] = i;ret[1] = j;return ret;}                }}return ret;}
}

方法2:

在这里插入图片描述

class Solution {public int[] twoSum(int[] nums, int target) {int[] ret = new int[2];HashMap<Integer,Integer> hash = new HashMap<>();// key:nums[i],value:ifor (int i = 0; i < nums.length; i++) {if (hash.containsKey(target - nums[i])) {ret[0] = i;ret[1] = hash.get(target - nums[i]);return ret;}hash.put(nums[i], i);}return ret;}
}

2、移动零

283. 移动零 - 力扣(LeetCode)

在这里插入图片描述

class Solution {public void moveZeroes(int[] nums) {int dest = -1;for (int cur = 0; cur < nums.length; cur++) {if (nums[cur] != 0) {dest++;int tmp = nums[cur];nums[cur] = nums[dest];nums[dest] = tmp;}}}
}

3、相交链表

160. 相交链表 - 力扣(LeetCode)

在这里插入图片描述

public class Solution {public ListNode getIntersectionNode(ListNode headA, ListNode headB) {ListNode cur1 = headA;ListNode cur2 = headB;int count1 = 0;//统计A结点个数int count2 = 0;//统计B结点个数while (cur1 != null) {count1++;cur1 = cur1.next;}while (cur2 != null) {count2++;cur2 = cur2.next;}if (count1 > count2) {for (int i = 0; i < count1 - count2; i++) {headA = headA.next;}}if (count1 < count2) {for (int i = 0; i < count2 - count1; i++) {headB = headB.next;}}while (headA != headB) {headA = headA.next;headB = headB.next;}return headA;}
}

4、有效的括号

20. 有效的括号 - 力扣(LeetCode)

在这里插入图片描述

class Solution {public boolean isValid(String s) {Stack<Character> stack = new Stack<>();for (int i = 0; i < s.length(); i++) {char ch = s.charAt(i);if (ch == '(' || ch == '[' || ch == '{') {//如果是左括号,入栈stack.push(ch);} else {//如果是右括号if (stack.empty()) {//判断栈是否为空return false;} else {char tmp = stack.peek();if (ch == ')' && tmp == '('|| ch == ']' && tmp == '['|| ch == '}' && tmp == '{') {stack.pop();} else {return false;}}}}return stack.empty();}
}

5、反转链表

206. 反转链表 - 力扣(LeetCode)

在这里插入图片描述

方法1:

class Solution {public ListNode reverseList(ListNode head) {if(head==null || head.next==null){return head;}        //1.先反转后面的链表ListNode newHead = reverseList(head.next);//返回反转后的头head.next.next = head;head.next = null;return newHead;}
}

方法2:

class Solution {public ListNode reverseList(ListNode head) {if (head == null) {return head;}ListNode cur = head.next;head.next = null;while (cur != null) {ListNode curNext = cur.next;cur.next = head;head = cur;cur = curNext;}return head;}
}

6、回文链表

234. 回文链表 - 力扣(LeetCode)

在这里插入图片描述

class Solution {public boolean isPalindrome(ListNode head) {if (head == null) {return false;}ListNode fast = head;ListNode slow = head;//找到中间结点while (fast != null && fast.next != null) {fast = fast.next.next;slow = slow.next;}ListNode Newhead = reverseList(slow);ListNode tmp1 = head;ListNode tmp2 = Newhead;while (tmp2 != null) {//if (tmp2.val != tmp1.val) {return false;} else {tmp1 = tmp1.next;tmp2 = tmp2.next;}}return true;}//翻转链表public ListNode reverseList(ListNode head) {if (head == null) {return head;}ListNode cur = head.next;head.next = null;while (cur != null) {ListNode curNext = cur.next;cur.next = head;head = cur;cur = curNext;}return head;}
}

7、环形链表

141. 环形链表 - 力扣(LeetCode)

在这里插入图片描述

public class Solution {public boolean hasCycle(ListNode head) {if (head == null) {return false;}ListNode fast = head.next;ListNode slow = head;while (fast != null && fast.next != null) {fast = fast.next.next;slow = slow.next;if (fast == slow) {return true;}}return false;}
}

8、环形链表II

142. 环形链表 II - 力扣(LeetCode)

在这里插入图片描述

public class Solution {public ListNode detectCycle(ListNode head) {if (head == null) {return null;}ListNode fast = head;ListNode slow = head;while (fast != null && fast.next != null) {fast = fast.next.next;slow = slow.next;if (fast == slow) {// 两人相遇,说明链表成环while (head != slow) {slow = slow.next;head = head.next;}//return head;}}return null;}
}

9、合并两个有序链表

21. 合并两个有序链表 - 力扣(LeetCode)

在这里插入图片描述

方法1:

class Solution {public ListNode mergeTwoLists(ListNode list1, ListNode list2) {if (list1 == null) {return list2;}if (list2 == null) {return list1;}// 1.比大小if (list1.val < list2.val) {list1.next = mergeTwoLists(list1.next, list2);return list1;} else {list2.next = mergeTwoLists(list2.next, list1);return list2;}}
}

方法2:

class Solution {public ListNode mergeTwoLists(ListNode list1, ListNode list2) {ListNode l1 = list1;ListNode l2 = list2;if (l1 == null) {return l2;}if (l2 == null) {return l1;}ListNode newHead = null;ListNode newTail = null;while (l1 != null && l2 != null) {if (l1.val <= l2.val) {//if (newTail == null) {newHead = newTail = l1;l1 = l1.next;} else {newTail.next = l1;newTail = l1;l1 = l1.next;}} else {if (newTail == null) {newHead = newTail = l2;l2 = l2.next;} else {newTail.next = l2;newTail = l2;l2 = l2.next;}}}//if (l1 == null) {newTail.next = l2;} else {newTail.next = l1;}return newHead;}
}

10、二叉树的中序遍历

94. 二叉树的中序遍历 - 力扣(LeetCode)

在这里插入图片描述

class Solution {List<Integer> ret = new LinkedList<Integer>();public List<Integer> inorderTraversal(TreeNode root) {        if (root == null) {return ret;}dfs(root, ret);return ret;}public void dfs(TreeNode root, List<Integer> ret) {if (root == null) {return;}dfs(root.left, ret);ret.add(root.val);dfs(root.right, ret);}
}

文章转载自:

http://SacH3x7y.wsnbg.cn
http://6hcb1hKZ.wsnbg.cn
http://2KhftDWN.wsnbg.cn
http://CYqBrd2u.wsnbg.cn
http://h2Z2Bhg2.wsnbg.cn
http://brnL0xwZ.wsnbg.cn
http://VsuyKUGe.wsnbg.cn
http://VnxPpDIu.wsnbg.cn
http://924GI3vG.wsnbg.cn
http://02TzUA7S.wsnbg.cn
http://ZybFrzOc.wsnbg.cn
http://i5Xahjr9.wsnbg.cn
http://7SnH2V8B.wsnbg.cn
http://L5myevdz.wsnbg.cn
http://T6jbdq3M.wsnbg.cn
http://EC7P8iNL.wsnbg.cn
http://jqUY1GAf.wsnbg.cn
http://xs9RHBSu.wsnbg.cn
http://oMG5tPl8.wsnbg.cn
http://l6nc4abh.wsnbg.cn
http://X0dwrRUh.wsnbg.cn
http://MlDtzjHO.wsnbg.cn
http://nnL0lYUT.wsnbg.cn
http://gCR1SEtx.wsnbg.cn
http://gjBLhNCx.wsnbg.cn
http://z1nhznXi.wsnbg.cn
http://IUXluiHS.wsnbg.cn
http://MDT3hZK2.wsnbg.cn
http://Lqm30bOR.wsnbg.cn
http://ylJT1o3s.wsnbg.cn
http://www.dtcms.com/wzjs/714196.html

相关文章:

  • 苏州门户网站有哪些公司画册模板
  • 电子政务网站建设公司礼品工艺品网站建设
  • 有专门学做衣服网站买网站空间
  • 浙江建设培训考试网站怎么健手机网站
  • 怎么添加网站内锚点wordpress 调用分类目录
  • wordpress开启用户登录无锡seo网站建设费用
  • 上海网站建设建议王也道长高清头像 微信
  • 建设专业网站哪家技术好番禺网站建设wwiw
  • 济南城乡建设官方网站怎么推广我的网站
  • 站长之家seo查询wordpress 替代文本
  • 深圳营销型网站建设公司选择哪家好?零元创业加盟网
  • 企业网站开发制作国外做宠物用品的网站
  • 中国沈阳网站在哪里下载一个好网站
  • html网站自带字体怎么做闵行网站制作哪里有
  • 网站开发用几种字体wordpress 应用监测
  • 网站建设saas我想在购物网站做代理
  • 贵州企业网站池州网站seo
  • 淘宝网站做多久程序开发工程师
  • 网页的网站建设在哪里提供网站建设公
  • 新万网站建设wordpress 微信login
  • 微信订阅号网站开发十大网页游戏排行
  • 亚马逊国际站官网arial 网站开发是用犀利
  • 海尔官网 网站建设的目标中国乐清新闻
  • 建立网站的技术wordpress 國内加速
  • 网站服务器转移视频吗免费活动网
  • win2003服务器网站管理工具wordpress推广自己淘宝店
  • 怎么做网站广告联盟网站建设一条龙源码
  • 个人网站搭建版权WordPress
  • 想用自己电脑做服务器做个网站吗梅州建站规划
  • 做响应式网站的流程网站建设刂金手指下拉十五