2024.4.27——LeetCode 高频题复盘

目录

  • 102. 二叉树的层序遍历
  • 33. 搜索旋转排序数组
  • 121. 买卖股票的最佳时机
  • 200. 岛屿数量
  • 20. 有效的括号
  • 88. 合并两个有序数组
  • 141. 环形链表
  • 46. 全排列
  • 236. 二叉树的最近公共祖先

102. 二叉树的层序遍历


题目链接

Python

方法一

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
        if not root:
            return []
        res=[]
        queue=[root]
        while queue:
            level_value=[]
            for _ in range(len(queue)):
                node=queue.pop(0)
                level_value.append(node.val)
                if node.left:
                    queue.append(node.left)
                if node.right:
                    queue.append(node.right)
            res.append(level_value)
        return res

方法二

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
        if not root:
            return []
        res=[]
        parent=[root]
        while parent:
            res.append([node.val for node in parent])
            child=[]
            for node in parent:
                if node.left:
                    child.append(node.left)
                if node.right:
                    child.append(node.right)
            parent=child
        return res

Java

方法一

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<List<Integer>> levelOrder(TreeNode root) {
        List<List<Integer>> res = new ArrayList<>();
        if (root == null) {
            return res;
        }
        
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);

        while (!queue.isEmpty()) {
            List<Integer> levelValue = new ArrayList<>();
            int levelSize = queue.size();
            for (int i = 0; i < levelSize; i++) {
                TreeNode node = queue.poll(); 
                levelValue.add(node.val);
                if (node.left != null) {
                    queue.add(node.left);
                }
                if (node.right != null) {
                    queue.add(node.right);
                }
            }
            res.add(levelValue);
        }
        return res;
    }
}

方法二

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<List<Integer>> levelOrder(TreeNode root) {
        List<List<Integer>> res = new ArrayList<>();
        if (root == null) {
            return res;
        }
        
        Queue<TreeNode> currentLevel = new LinkedList<>();
        currentLevel.add(root);

        while (!currentLevel.isEmpty()) {
            List<Integer> levelValues = new ArrayList<>();
            Queue<TreeNode> nextLevel = new LinkedList<>();

            while (!currentLevel.isEmpty()) {
                TreeNode node = currentLevel.poll();
                levelValues.add(node.val);
                if (node.left != null) {
                    nextLevel.add(node.left);
                }
                if (node.right != null) {
                    nextLevel.add(node.right);
                }
            }

            res.add(levelValues);
            currentLevel = nextLevel;
        }
        return res;
    }
}

33. 搜索旋转排序数组


题目链接

Python

class Solution:
    def search(self, nums: List[int], target: int) -> int:
        l,r=0,len(nums)-1
        while l<=r:
            mid=(l+r)//2
            if target==nums[mid]:
                return mid
            if nums[l]<=nums[mid]: # 左半部分有序
                if nums[l]<=target<nums[mid]:
                    r=mid-1
                else:
                    l=mid+1
            else: # 右半部分有序
                if nums[mid]<target<=nums[r]:
                    l=mid+1
                else:
                    r=mid-1
        return -1

Java

public class Solution {
    public int search(int[] nums, int target) {
        int l = 0, r = nums.length - 1;
        
        while (l <= r) {
            int mid = l + (r - l) / 2;
            if (nums[mid] == target) {
                return mid;
            }

            if (nums[l] <= nums[mid]) {
                if (nums[l] <= target && target < nums[mid]) {
                    r = mid - 1;
                } else {
                    l = mid + 1;
                }
            } 
            else {
                if (nums[mid] < target && target <= nums[r]) {
                    l = mid + 1;
                } else {
                    r = mid - 1;
                }
            }
        }
        return -1; 
    }
}

121. 买卖股票的最佳时机


题目链接

Python

class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        # 每一天的股票都有两种状态:dp[i][0]不持有,dp[i][1]持有
        dp=[[0,0] for _ in range(len(prices))]
        dp[0][1]=-prices[0]
        for i in range(1,len(prices)):
            dp[i][0]=max(dp[i-1][0],dp[i-1][1]+prices[i]) # 不持有
            dp[i][1]=max(dp[i-1][1],-prices[i]) # 持有
        return dp[len(prices)-1][0]

Java

public class Solution {
    public int maxProfit(int[] prices) {
        int n = prices.length;
        int[][] dp = new int[n][2];
        dp[0][1] = -prices[0];  
        for (int i = 1; i < n; i++) {
            dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1] + prices[i]); // 不持有
            dp[i][1] = Math.max(dp[i - 1][1], -prices[i]);              // 持有
        }
        // 最后一天不持有股票的情况即为最大利润
        return dp[n - 1][0];
    }
}

200. 岛屿数量


题目链接

Python

DFS 解法

class Solution:
    def numIslands(self, grid: List[List[str]]) -> int:
        def dfs(x,y):
            visited[x][y]=True # 核心
            for d in dirs:
                nx=x+d[0]
                ny=y+d[1]
                if 0<=nx<m and 0<=ny<n and not visited[nx][ny] and grid[x][y]=='1':
                    dfs(nx,ny)
        m,n=len(grid),len(grid[0])
        visited=[[False]*n for _ in range(m)]
        dirs=[(-1,0),(1,0),(0,-1),(0,1)] # 上下左右
        res=0
        for i in range(m):
            for j in range(n):
                if not visited[i][j] and grid[i][j]=='1':
                    res+=1
                    dfs(i,j) # 将与其连接的陆地都标记为True(已经访问过)
        return res

BFS 解法

class Solution:
    from collections import deque
    def numIslands(self, grid: List[List[str]]) -> int:
        def bfs(x,y):
            q=deque()
            q.append((x,y))
            visited[x][y]=True
            while q:
                x,y=q.popleft()
                for d in dirs:
                    nx,ny=x+d[0],y+d[1]
                    if 0<=nx<m and 0<=ny<n and not visited[nx][ny] and grid[x][y]=='1':
                        q.append((nx,ny))
                        visited[nx][ny]=True
        m,n=len(grid),len(grid[0])
        visited=[[False]*n for _ in range(m)]
        dirs=[(-1,0),(1,0),(0,-1),(0,1)] # 上下左右
        res=0
        for i in range(m):
            for j in range(n):
                if not visited[i][j] and grid[i][j]=='1':
                    res+=1
                    bfs(i,j) # 将与其连接的陆地都标记为True(已经访问过)
        return res

Java

DFS 解法

public class Solution {
    public int numIslands(char[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        boolean[][] visited = new boolean[m][n];
        int[][] dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; // 上下左右
        int res = 0;

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (!visited[i][j] && grid[i][j] == '1') {
                    res++;
                    dfs(grid, visited, i, j, dirs);
                }
            }
        }
        return res;
    }

    private void dfs(char[][] grid, boolean[][] visited, int x, int y, int[][] dirs) {
        visited[x][y] = true;
        int m = grid.length;
        int n = grid[0].length;

        for (int[] d : dirs) {
            int nx = x + d[0];
            int ny = y + d[1];
            if (0 <= nx && nx < m && 0 <= ny && ny < n && !visited[nx][ny] && grid[nx][ny] == '1') {
                dfs(grid, visited, nx, ny, dirs);
            }
        }
    }
}

BFS 解法

public class Solution {
    public int numIslands(char[][] grid) {

        int m = grid.length;
        int n = grid[0].length;
        boolean[][] visited = new boolean[m][n];
        int[][] dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; // 上下左右
        int res = 0;

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (!visited[i][j] && grid[i][j] == '1') {
                    res++;
                    bfs(grid, visited, i, j, dirs);
                }
            }
        }
        return res;
    }

    private void bfs(char[][] grid, boolean[][] visited, int x, int y, int[][] dirs) {
        int m = grid.length;
        int n = grid[0].length;

        Queue<int[]> queue = new LinkedList<>();
        queue.add(new int[]{x, y});
        visited[x][y] = true;

        while (!queue.isEmpty()) {
            int[] point = queue.poll();
            int curX = point[0];
            int curY = point[1];

            for (int[] d : dirs) {
                int nx = curX + d[0];
                int ny = curY + d[1];
                if (0 <= nx && nx < m && 0 <= ny && ny < n && !visited[nx][ny] && grid[nx][ny] == '1') {
                    queue.add(new int[]{nx, ny});
                    visited[nx][ny] = true;
                }
            }
        }
    }
}

20. 有效的括号


题目链接

class Solution:
    def isValid(self, s: str) -> bool:
        if len(s)%2!=0:
            return False
        dic={
            ")":"(",
            "}":"{",
            "]":"["
        }
        stack=[]
        for c in s:
            # 右括号都看栈里面是否有相应的左括号
            if c in dic:
                # 栈里面没有对应的左括号
                if not stack or stack[-1]!=dic[c]:
                    return False
                # 栈里面有对应的左括号,成对的左右括号相消
                else:
                    stack.pop()
            # 左括号都入栈
            else:
                stack.append(c)
        return not stack

Java

class Solution {
    public boolean isValid(String s) {
        if (s.length()%2!=0){
            return false;
        }
        HashMap<Character,Character> hashmap=new HashMap<>();
        hashmap.put(')','(');
        hashmap.put('}','{');
        hashmap.put(']','[');
        Stack<Character> stack=new Stack<>();
        for (char c:s.toCharArray()){
            if (hashmap.containsKey(c)){
                if (stack.isEmpty() || stack.peek()!=hashmap.get(c)){
                    return false;
                }else{
                    stack.pop();
                }
            }else{
                stack.push(c);
            }
        }
        return stack.isEmpty();
    }
}

88. 合并两个有序数组


题目链接

Python

class Solution:
    def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
        """
        Do not return anything, modify nums1 in-place instead.
        """
        p1,p2=m-1,n-1
        tail=m+n-1
        while p1>=0 or p2>=0:
            if p1==-1:
                nums1[tail]=nums2[p2]
                p2-=1
            elif p2==-1:
                nums1[tail]=nums1[p1]
                p1-=1
            elif nums1[p1]<=nums2[p2]:
                nums1[tail]=nums2[p2]
                p2-=1
            else:
                nums1[tail]=nums1[p1]
                p1-=1
            tail-=1

Java

class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int p1=m-1;
        int p2=n-1;
        int tail=m+n-1;
        while (p1>=0 || p2>=0){
            if (p1==-1){
                nums1[tail]=nums2[p2];
                p2-=1;
            }else if (p2==-1){
                nums1[tail]=nums1[p1];
                p1-=1;
            }else if (nums1[p1]<=nums2[p2]){
                nums1[tail]=nums2[p2];
                p2-=1;
            }else{
                nums1[tail]=nums2[p1];
                p1-=1;
            }
        tail-=1;
        }
    }
}

141. 环形链表


题目链接

Python

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def hasCycle(self, head: Optional[ListNode]) -> bool:
        slow,fast=head,head
        while fast and fast.next:
            slow=slow.next
            fast=fast.next.next
            if slow==fast:
                return True
        return False

Java

/**
 * Definition for singly-linked list.
 * class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Solution {
    public boolean hasCycle(ListNode head) {
        ListNode slow=head;
        ListNode fast=head;
        while (fast!=null && fast.next!=null){
            fast=fast.next.next;
            slow=slow.next;
            if(slow==fast){
                return true;
            }
        }
        return false;
    }
}

注意:在Java中,while (fast != null && fast.next != null)不能写成 while (fast && fast.next) 这种语法。Java 对布尔表达式的要求是明确且严格的,它要求表达式明确地返回一个布尔值。

46. 全排列


题目链接

Python

class Solution:
    def permute(self, nums: List[int]) -> List[List[int]]:
        path=[]
        res=[]
        def backtracing(nums,used):
            if len(path)==len(nums):
                res.append(path[:])
            for i in range(len(nums)):
                if not used[i]:
                    path.append(nums[i])
                    used[i]=True
                    backtracing(nums,used)
                    used[i]=False
                    path.pop()
        used=[False]*(len(nums))
        backtracing(nums,used)
        return res

Java

class Solution {
    public List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        boolean[] used =new boolean[nums.length];
        backtracking(nums,used,path,res);
        return res;
    }
    public void backtracking(int[] nums,boolean[] used, List<Integer> path,List<List<Integer>> res){
        if (path.size()==nums.length){
            res.add(new ArrayList<>(path));
        }
        for(int i=0;i<nums.length;i++){
            if (!used[i]){
                path.add(nums[i]);
                used[i]=true;
                backtracking(nums,used,path,res);
                used[i]=false;
                path.remove(path.size()-1);
            }
        }
    }
}

注意:Java写法中 path.remove(path.size()-1);不能写成 path.remove(nums[i]);。因为nums[i]是基本类型,Java 实际上会将 nums[i] 视为一个整数,并尝试将其作为索引来移除 path 列表中对应索引处的元素。如果确实需要根据值来移除元素,并且该值是一个对象(这里是 Integer)path.remove(Integer.valueOf(nums[i])); // 创建一个Integer对象,并尝试移除这个对象

236. 二叉树的最近公共祖先


题目链接

Python

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
        if not root or p==root or q==root:
            return root
        # 后序遍历
        left=self.lowestCommonAncestor(root.left,p,q)
        right=self.lowestCommonAncestor(root.right,p,q)
        if left and right:
            return root
        elif not left and right:
            return right
        elif not right and left:
            return left
        else:
            return    

Java

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        if (root==null || p==root || q==root){
            return root;
        }
        TreeNode left = lowestCommonAncestor(root.left,p,q);
        TreeNode right = lowestCommonAncestor(root.right,p,q);
        if (left!=null && right!=null){
            return root;
        }else if (left!=null && right==null){
            return left;
        }else if (left==null && right!=null){
            return right;
        }else{
            return null;
        }
    }
}

注意:在Java中,不能使用 and 和 or 这样的关键字来表示逻辑运算。Java使用符号 &&(逻辑与)和 ||(逻辑或)来执行逻辑运算。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/580548.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【新手入门】Git的使用方法,上传自己的项目到GitHub上

Git新手教程 一、Git下载安装二、初始化设置1.网端设置2.用户设置 三、开始上传自己项目1.创建新文件夹&#xff0c;克隆项目地址2.上传文件3.成功运行并上传的界面 报错1.fatal: unable to access https://github.com/ssrzero123/STF-YOLO.git/: error setting certificate fi…

mars3d开发过程中点击面图层飞行定位,设置俯仰角度后,layer.flyTo({没有生效的排查思路

mars3d开发过程中点击面图层飞行定位&#xff0c;设置俯仰角度后&#xff0c;layer.flyTo({没有生效的排查思路记录&#xff0c;给大家提供一下以后排查定位问题的方向 问题场景相关代码&#xff1a; 1.项目本身代码&#xff1a; 2.精简了关键性代码后&#xff0c;就可以去ge…

39-数组 _ 二维数组

39-1 二维数组的创建 行和列编号依旧是从0开始&#xff1a; //arr数组&#xff1a; //1 2 3 4 //2 3 4 5 //2 4 5 6 //三行四列int main() {int arr[3][4]; //存放整数char arr1[5][10]; //存放字符return 0; } 39-2 二维数组的初始化 创建之后&#xff0c;利用初始化赋值…

MySQL-多表查询-练习

练习 1.写一个查询显示所有雇员的 last name、department id、anddepartment name。 SELECT e.LAST_NAME,e.DEPARTMENT_ID,d.DEPARTMENT_NAME FROM employees e,departments d WHERE e.DEPARTMENT_ID d.DEPARTMENT_ID;2.创建一个在部门 80 中的所有工作岗位的唯一列表&#x…

我与C++的爱恋:模板初阶和STL库

​ ​ &#x1f525;个人主页&#xff1a;guoguoqiang. &#x1f525;专栏&#xff1a;我与C的爱恋 ​朋友们大家好&#xff0c;本篇文章介绍一下模版和对STL进行简单的介绍&#xff0c;后续我们进入对STL的学习&#xff01; ​ 一、模板 1.泛型模板 泛型编程&#xff1a;…

PotatoPie 4.0 实验教程(23) —— FPGA实现摄像头图像伽马(Gamma)变换

为什么要进行Gamma校正 图像的 gamma 校正是一种图像处理技术&#xff0c;用于调整图像的亮度和对比度&#xff0c;让显示设备显示的亮度和对比度更符合人眼的感知。Gamma 校正主要用于修正显示设备的非线性响应&#xff0c;以及在图像处理中进行色彩校正和图像增强。 以前&am…

unity学习(91)——云服务器调试——补充catch和if判断

本机局域网没问题&#xff0c;服务器放入云服务器后&#xff0c;会出现异常。 想要找到上面的问题&#xff0c;最简单的方法就是在云服务器上下载一个vs2022&#xff01; 应该不是大小端的问题&#xff01; 修改一下readMessage的内容&#xff0c;可以直接粘贴到云服务器的。 …

AIGC技术的伦理与风险探讨:现状与未来

如何看待AIGC技术&#xff1f; 简介&#xff1a;探讨AIGC技术的发展现状和未来趋势。 随着人工智能的迅速发展&#xff0c;AIGC&#xff08;Artificial Intelligence in General Computing&#xff09;技术作为智能计算的一种形式&#xff0c;正逐渐渗透到我们的生活和工作中…

firebase:一款功能强大的Firebase数据库安全漏洞与错误配置检测工具

关于firebase firebase是一款针对Firebase数据库的安全工具&#xff0c;该工具基于Python 3开发&#xff0c;可以帮助广大研究人员针对目标Firebase数据库执行安全漏洞扫描、漏洞测试和错误配置检测等任务。 该工具专为红队研究人员设计&#xff0c;请在获得授权许可后再进行安…

OpenCV添加文字和水印------c++

添加文字 bool opencvTool::addText(cv::Mat& image, const std::string text, const cv::Point& position, double fontScale, cv::Scalar color, int thickness, int fontFace) {cv::putText(image, text, position, fontFace, fontScale, color, thickness);return…

HTML5+CSS3小实例:飞行滑块

实例:飞行滑块 技术栈:HTML+CSS 效果: 源码: 【HTML】 <!DOCTYPE html> <html lang="zh-CN"> <head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0&qu…

利用STM32实现语音识别功能

引言 随着物联网和智能设备的普及&#xff0c;语音识别技术正逐渐成为用户交互的主流方式之一。 STM32微控制器具备处理高效率语音识别算法的能力&#xff0c;使其成为实现低成本、低功耗语音交互系统的理想选择。 本教程将介绍如何在STM32平台上开发和部署一个基础的语音识…

CentOS系统服务器装机后常用的操作命令大全

博主猫头虎的技术世界 &#x1f31f; 欢迎来到猫头虎的博客 — 探索技术的无限可能&#xff01; 专栏链接&#xff1a; &#x1f517; 精选专栏&#xff1a; 《面试题大全》 — 面试准备的宝典&#xff01;《IDEA开发秘籍》 — 提升你的IDEA技能&#xff01;《100天精通鸿蒙》 …

3分钟入门Java多线程

如何在程序中创建出多条线程&#xff1f; 继承Thread类 public class MyThread extends Thread {Overridepublic void run() {for (int i 0; i < 10; i) {System.out.println("MyThread运行了" i);}} }实现Runnable接口 public class MyRunnable implements …

js的算法-插入排序(折半插入排序)

直接插入排序的步骤 1. 从前面的有序子表中查找出待插入元素应该被插入的位置 2. 给插入位置腾空间 3. 将待插入元素复制到表中的插入位置。 直接插入排序&#xff1a;边比较边移动&#xff1b; 折半插入排序 先折半查找出元素的待插入位置&#xff0c;然后统一地移动待插…

Windows系统中下Oracle 19C数据库超级详细安装、设置教程(自己电脑上安装Oracle学习,保姆级教学,亲测有效)

Oracle 官方提供了一个基于 Java 技术的图形界面安装工具&#xff1a;Oracle Universal Installer&#xff08;Oracle 通用安装器&#xff09;简称 OUI&#xff0c;利用它可以完成在不同操作系统平台上&#xff08;Windows、Linux、UNIX&#xff09;的、不同类型的、不同版本的…

kotlin 编写一个简单的天气预报app (七)使用material design

一、优化思路 对之前的天气预报的app进行了优化&#xff0c;原先的天气预报程序逻辑是这样的。 使用text和button组合了一个输入城市&#xff0c;并请求openweathermap对应数据&#xff0c;并显示的功能。 但是搜索城市的时候&#xff0c;可能会有错误&#xff0c;比如大小写…

Java设计模式 _结构型模式_过滤器模式

一、过滤器模式 1、过滤器模式 过滤器模式&#xff08;Filter Pattern&#xff09;是这一种结构型设计模式。过滤器&#xff0c;顾名思义&#xff0c;就是对一组数据进行过滤&#xff0c;从而最终获取到我们预期的数据。 2、实现思路 &#xff08;1&#xff09;、定义过滤器的…

解决问题:Canal客户端覆盖服务端Subscribe,只有TRANSACTIONBEGIN和TRANSACTIONEND日志,没有ROWDATA日志的问题

一&#xff0c;背景 在整合canal和Spring时&#xff0c;本地使用canal的subscribe方法订阅了需要监听的表&#xff0c;但是获得只有transactionbegin和transactionend两种eventType的日志&#xff0c; 没有rowdata类型的日志&#xff0c;导致无法完成监听数据库数据更新的需求…

提示词优化的自动化探索:Automated Prompt Engineering

编者按&#xff1a; 作者在尝试教授母亲使用 LLM 完成工作任务时&#xff0c;意识到提示词的优化并不像想象中简单。提示词的自动优化对于经验并不丰富的提示词撰写者很有价值&#xff0c;他们没有足够的经验去调整和改进提供给模型的提示词&#xff0c;这引发了对自动化提示词…