剑指offer
Katrina~
哇你好鸭
展开
-
剑指 Offer 26. 树的子结构
jz原创 2022-09-28 23:11:38 · 87 阅读 · 0 评论 -
Leetcode 剑指 Offer 18. 删除链表的节点
jz原创 2022-09-04 23:17:42 · 120 阅读 · 0 评论 -
Leetcode 96. 不同的二叉搜索树
Leetcode原创 2022-09-02 17:31:50 · 68 阅读 · 0 评论 -
剑指 Offer 28. 对称的二叉树
剑指offer原创 2022-09-01 20:49:56 · 1022 阅读 · 0 评论 -
最长递增子序列
算法原创 2022-08-18 18:54:42 · 103 阅读 · 0 评论 -
剑指 Offer II 091. 粉刷房子
leetcode原创 2022-08-06 19:52:09 · 73 阅读 · 0 评论 -
剑指 Offer 14- I. 剪绳子
jz原创 2022-08-01 21:19:16 · 75 阅读 · 0 评论 -
剑指 Offer 03. 数组中重复的数字
算法流程:遍历数组 numsnums ,设索引初始值为 i = 0i=0 :若 nums[i] = inums[i]=i : 说明此数字已在对应索引位置,无需交换,因此跳过;若 nums[nums[i]] = nums[i]nums[nums[i]]=nums[i] : 代表索引 nums[i]nums[i] 处和索引 ii 处的元素值都为 nums[i]nums[i] ,即找到一组重复值,返回此值 nums[i]nums[i] ;否则: 交换索引为 ii 和 nums[i]nums[i] 的元素值原创 2022-05-12 21:07:58 · 105 阅读 · 0 评论 -
剑指 Offer-反转链表的3种方式
参考剑指 Offer-反转链表的3种方式方式一:栈import java.util.Stack;public class Solution {public ListNode ReverseList(ListNode head) { Stack<ListNode> stack= new Stack<>(); //把链表节点全部摘掉放到栈中 while (head != null) { stack.push(head); h原创 2022-04-20 19:14:46 · 130 阅读 · 0 评论 -
JZ22 链表中倒数最后k个结点
import java.util.*;public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param pHead ListNode类 * @param k int整型 * @return ListNode类 */ public ListNode FindKthToTail (ListNode pHead, int k)原创 2022-04-20 15:36:57 · 692 阅读 · 0 评论 -
JZ25 合并两个排序的链表
迭代public class Solution { public ListNode Merge(ListNode list1,ListNode list2) { if(list1==null){ return list2; } else if(list2==null){ return list1; } ListNode dummy=new ListNode(-1);原创 2022-04-19 11:16:01 · 55 阅读 · 0 评论 -
JZ28 对称的二叉树
public class Solution { boolean isSymmetrical(TreeNode pRoot) { return check(pRoot,pRoot); } boolean check(TreeNode a,TreeNode b){ if(a==null&&b==null) return true; else if(a==null||b==null) return false;原创 2022-04-15 11:46:33 · 473 阅读 · 0 评论 -
JZ27 二叉树的镜像
import java.util.*;public class Solution { public TreeNode Mirror (TreeNode pRoot) { // write code here if(pRoot==null) return pRoot; Stack<TreeNode>s=new Stack<>(); s.add(pRoot); while(!s.empty()){原创 2022-04-12 20:56:11 · 416 阅读 · 0 评论 -
JZ21 调整数组顺序使奇数位于偶数前面(一)
class Solution {public: vector<int> reOrderArray(vector<int>& array) { int p=0; for(int i=0;i<array.size();i++){ if(array[i]%2){ int tmp=array[i]; for(int j=i-1;j>=p;j--原创 2022-04-12 20:35:40 · 129 阅读 · 0 评论 -
JZ4 二维数组中的查找
class Solution {public: bool Find(int target, vector<vector<int> > array) { int n=array.size(); int m=array[0].size(); if(!n||!m) return false; int t=0,r=n-1; while(t<n&&r>=0){原创 2022-04-10 09:52:20 · 129 阅读 · 0 评论 -
JZ31 栈的压入、弹出序列
class Solution {public: bool IsPopOrder(vector<int> pushV,vector<int> popV) { stack<int>q; int i=0,j=0; int len=popV.size(); while(i<len){ if(pushV[i]!=popV[j]){ q.push(p原创 2022-04-10 09:46:18 · 120 阅读 · 0 评论 -
JZ18 删除链表的节点
/*public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; }}*/public class Solution { public ListNode ReverseList(ListNode head) { //pre指针:用来指向反转后的节点,初始化为null ListNode pre =原创 2022-04-09 19:04:45 · 505 阅读 · 0 评论 -
JZ9 用两个栈实现队列
class Solution{public: void push(int node) { stack1.push(node); } int pop() { if (stack2.empty()) { while (!stack1.empty()) { stack2.push(stack1.top()); stack1.pop(); }原创 2022-04-08 22:45:45 · 182 阅读 · 0 评论 -
JZ18 删除链表的节点
方法一-双指针class Solution { public ListNode deleteNode(ListNode head, int val) { if(head.val == val)return head.next; ListNode pre = head, cur = head.next; while(cur != null && cur.val != val){ pre = cur;原创 2022-04-08 14:41:56 · 1341 阅读 · 0 评论 -
JZ11 旋转数组的最小数字
class Solution {public: int minNumberInRotateArray(vector<int> n) { int low=0,high=n.size()-1; while(low<high){ int mid=low+(high-low)/2; if(n[mid]>n[high]){ low=mid+1; }原创 2022-04-07 11:58:40 · 243 阅读 · 0 评论 -
JZ53 数字在升序数组中出现的次数
upper_boundlower_bound用法标记class Solution {public: int GetNumberOfK(vector<int> data ,int k) { int l = 0, r = data.size(); //寻找下界 while(l < r){ int m = l + (r - l)/2; if(data[m] < k){原创 2022-04-06 21:16:13 · 296 阅读 · 0 评论 -
剑指offer 树总结
JZ55 二叉树的深度解法一:bfsimport java.util.*;public class Solution { public int TreeDepth(TreeNode root) { Queue<TreeNode> list = new LinkedList<TreeNode>(); if(root == null){ return 0; } int level = 0;原创 2022-04-06 19:03:27 · 797 阅读 · 0 评论 -
二叉树的递归中序遍历
二叉树的递归中序遍历java代码:class Solution { private void inorderTraversal(TreeNode treeNode,List<Integer>list){ if(treeNode==null) return; inorderTraversal(treeNode.left,list); list.add(treeNode.val); inorderTraversal(treeN原创 2022-04-06 18:27:54 · 621 阅读 · 0 评论 -
剑指offer JZ73 翻转单词序列
import java.util.*;public class Solution { public String ReverseSentence(String str) { if(str.isEmpty()){ return str; } String[] word = new String[str.length()]; Stack stack = new Stack<>(); wo原创 2022-04-06 16:30:25 · 122 阅读 · 0 评论 -
剑指offer JZ45 把数组排成最小的数
class Solution {public: static bool cmp(int x,int y){ string tmp1=to_string(x); string tmp2=to_string(y); string s1=tmp1,s2=tmp2; s1+=tmp2; s2+=tmp1; return s1<s2; } st原创 2022-04-06 10:35:42 · 132 阅读 · 0 评论 -
剑指offer JZ73 翻转单词序列
class Solution {public: string ReverseSentence(string str) { if(str.empty()) return str; string s=""; string ret="";//最终的结果 bool b=false; int sz = str.size(); for(int i=sz-1;i>=0;i--){ if(原创 2022-04-05 23:14:19 · 270 阅读 · 0 评论 -
剑指offe JZ18 删除链表的节点
删除节点操作:设前驱节点为pre,当前节点为cur即将前一个节点的后驱指向被删除节点的后驱pre->next=cur->next;算法流程:边界:当第一个节点为目标节点,直接head=head->next;初始化:pre=head cur=head->nextclass Solution { public ListNode deleteNode(ListNode head, int val) { if(head.val == val)retur原创 2022-04-05 23:12:17 · 312 阅读 · 0 评论 -
剑指offer JZ29 顺时针打印矩阵
class Solution {public: vector<int> printMatrix(vector<vector<int> > matrix) { vector<int>q; int top=0,down=matrix.size()-1,left=0,right=matrix[0].size()-1; while(1){ for(int i=left;i<=r原创 2022-04-05 14:22:37 · 131 阅读 · 0 评论