• 2023-09-06力扣每日一题-摆烂暴力


    链接:

    [1123. 最深叶节点的最近公共祖先](https://leetcode.cn/problems/form-smallest-number-from-two-digit-arrays/)

    题意:

    如题

    解:

    今天搞一手暴力,按层存,按层取,直到只取到一个

    实际代码:

    #include
    using namespace std;
    int minNumber(vector& nums1, vector& nums2)
    {
        short book[10];for(auto& b:book) b=0;
        
        int min1=INT_MAX,min2=INT_MAX;
        for(auto num:nums1) { book[num]++;min1=min(min1,num); }
        for(auto num:nums2) { book[num]++;min2=min(min2,num); }
        
        for(int i=1;i<=9;i++) if(book[i]>=2) return i;
        
        return min(min1,min2)*10+max(min1,min2);
    }
    int main()
    {
    	int a,b,num;cin>>a>>b;
    	vector nums1, vector nums2;
    	while(a--)
    	{
    		cin>>num;
    		nums1.push_back(num);
    	}
    	while(b--)
    	{
    		cin>>num;
    		nums2.push_back(num);
    	}
    	int ans=minNumber(num1,num2);
    	cout<
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    限制:

    • 树中的节点数将在 [1, 1000] 的范围内。
    • 0 <= Node.val <= 1000
    • 每个节点的值都是 独一无二 的。
  • 相关阅读:
    spring5.3 十四:spring AOP源码分析
    电力电子转战数字IC20220728day58——uvm入门实验5
    【C语言】内存函数——按字节拷贝
    LeetCode每日一题(874. Walking Robot Simulation)
    Redis-企业级解决方案
    【计算机网络】TCP为什么需要3次握手
    Harbor webhook从原理到构建
    003-JavaSE基础巩固练习:if语句练习
    图解LeetCode——1608. 特殊数组的特征值(难度:简单)
    《龙湖地产》企业门户网站前端设计(Html,CSS,JavaScript,jQuery)
  • 原文地址:https://blog.csdn.net/Fei_WuYan/article/details/132725753