zoukankan      html  css  js  c++  java
  • LeetCode刷题191125

    博主渣渣一枚,刷刷leetcode给自己瞅瞅,大神们由更好方法还望不吝赐教。题目及解法来自于力扣(LeetCode),传送门

      今天状态不好,划一下水。

    算法:

    给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。

    你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。

    示例:

    给定 nums = [2, 7, 11, 15], target = 9

    因为 nums[0] + nums[1] = 2 + 7 = 9
    所以返回 [0, 1]

    public class Solution {
        public int[] TwoSum(int[] nums, int target) {
            for(int i = 0; i < nums.Length - 1; i++)
            {
                for(int j = i + 1; j < nums.Length; j ++)
                {
                    if(nums[i] + nums[j] == target)
                    {
                        return new int[2] {i, j};
                    }
                }
            }
            
            return null;
        }
    }

      这道题太简单了,不多BB了。

    数据库:

    给定一个 Weather 表,编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 Id。

    +---------+------------------+------------------+
    | Id(INT) | RecordDate(DATE) | Temperature(INT) |
    +---------+------------------+------------------+
    | 1 | 2015-01-01 | 10 |
    | 2 | 2015-01-02 | 25 |
    | 3 | 2015-01-03 | 20 |
    | 4 | 2015-01-04 | 30 |
    +---------+------------------+------------------+
    例如,根据上述给定的 Weather 表格,返回如下 Id:

    +----+
    | Id |
    +----+
    | 2 |
    | 4 |
    +----+

    SELECT
        Weather.id AS 'Id'
    FROM
        Weather
            JOIN
        Weather w ON DATEDIFF(Weather.RecordDate, w.RecordDate) = 1
            AND Weather.Temperature > w.Temperature

      很简单的题,好玩的点在于MySQL中DATEDIFF函数的使用. Mysql其实本身提供了许多函数来进行这一类的处理。

  • 相关阅读:
    【Cloud Foundry】Could Foundry学习(二)——核心组件分析
    POJ 1789-Truck History
    设置静态IP
    oracle切割字符串后以单列多行展示
    SQL server语句练习
    hdu 3308 LCIS(线段树)
    HDU 1556 Color the Ball 线段树 题解
    CSipSimple最新版本号
    奢侈品行业-新手专题-亿邦动力网
    单身潮_百度百科
  • 原文地址:https://www.cnblogs.com/dogtwo0214/p/11929392.html
Copyright © 2011-2022 走看看