找LeetCode上简单的题目来撑过30天啦(DAY3)

各位中秋节连假愉快,我今天坐客运,还包车了呢,司机先生只载我一个人,运气不错,好啦今天也要继续努力解题罗

今天的第一题,莫名其妙选到SQL题了呢,题目我真的都是乱选的,看哪个题目看起来比较亲切,然後内容感觉上是我写得出来的,好啦上题目
题号:183 标题:Customers Who Never Order 难度:Easy

题目内容:
Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.
Table: Customers.
+----+-------+
| Id | Name |
+----+-------+
| 1 | Joe |
| 2 | Henry |
| 3 | Sam |
| 4 | Max |
+----+-------+
Table: Orders.
+----+------------+
| Id | CustomerId |
+----+------------+
| 1 | 3 |
| 2 | 1 |
+----+------------+
Using the above tables as example, return the following:
+-----------+
| Customers |
+-----------+
| Henry |
| Max |
+-----------+

我的SQL指令

select Customers.Name Customers  from Customers WHERE Customers.Id NOT IN(SELECT Orders.CustomerId from Orders)

用到重新命名栏位跟NOT IN,痾,这题没甚麽说的,就再来一题吧

题号:283 标题:Move Zeroes 难度:Easy
题目内仍:
Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.
Note that you must do this in-place without making a copy of the array.

Example 1:
Input: nums = [0,1,0,3,12]
Output: [1,3,12,0,0]
Example 2:
Input: nums = [0]
Output: [0]

Constraints:
• 1 <= nums.length <= 104
• -231 <= nums[i] <= 231 - 1

Follow up: Could you minimize the total number of operations done?

我的程序码

void moveZeroes(int* nums, int numsSize){
    int i =0,count=0,count2,j;
    
     for(i=0;i<numsSize;i++){ //计算多少个0
        if(nums[i]==0){
            count++;
        }
    }
    count2=numsSize-count;//多少个非0
    j=0;
    for(i=0;i<numsSize;i++){ 
        
        if(nums[i] !=  0){
            nums[j] = nums[i]; //把非0塞到前面去
            count2=count2-1;
            j++;
            if(i >= numsSize-count){ //当i已经过了非0的idex,全塞0
                nums[i] = 0;
            }
        }
    }
    
    return nums;
}

花比较久的时间
在於怎麽把正确的0的数量补上
其实这题我也是最直观的解法,先计算非0的各数,然後再把非0的数值填回去,当都填完以後,其他的全部塞0。

DAY3心得
不知不觉第三天来罗,渐入佳境,大家加油阿,晚安


<<:  Day 4 重新定位与节

>>:  Day 6 - 二进位会不会被禁位?

Day 1 : 前言与DevOps

前言 大家好,我是Lufor,第一次参加铁人赛。这是我的主要Blog网址: https://lufo...

Golang快速入门(Day4)

在这边要介绍一下go的基本用法 而这些用法在A Tour of Go也都有介绍 在下面的程序码如果有...

Day 28 - 上架 App 到 Google Play Store for Android TV Part 1

不知道大家有没有试过 在手机上的 App 觉得很好用,想找找看是否可以安装在 TV 上 但去了 Go...

【Day 3】Git x GitHub x 版本控制的基础:吴宝春的成功秘诀

tags: 铁人赛 Git GitHub 版本控制 概述 碎念时间 为什麽我们需要 版本控制 ? 每...

javascript函式教学3

接下来我们来写一个范例程序,写出1加到50乘以1加到100。 注意:如果程序没有回传值,getsum...