zoukankan      html  css  js  c++  java
  • leetcode-每日打卡-day 9

    leetcode 每日打卡

    those times when you get up early and you work hard; those times when you stay up late and you work hard; those times when don’t feel like working — you’re too tired, you don’t want to push yourself — but you do it anyway. That is actually the dream. That’s the dream. It’s not the destination, it’s the journey. And if you guys can understand that, what you’ll see happen is that you won’t accomplish your dreams, your dreams won’t come true, something greater will. mamba out


    那些你早出晚归付出的刻苦努力,你不想训练,当你觉的太累了但还是要咬牙坚持的时候,那就是在追逐梦想,不要在意终点有什么,要享受路途的过程,或许你不能成就梦想,但一定会有更伟大的事情随之而来。 mamba out~

    2020.2.19


    记录下来自己做题时得思路,并不一定是最优解

    1351. 统计有序矩阵中的负数

    class Solution {
    public:
        // 最小值中找最大 (又半区间) l = mid ,l + r + 1 >> 1
        int merge(vector<int> nums)
        {
            int l = 0,r = nums.size() - 1;
            while(l < r)
            {
                int mid = l + r + 1 >> 1;
                if(nums[mid] >= 0)l = mid;
                else r = mid - 1;
            }
            if(nums[l] >= 0){
                return nums.size() - l - 1;
            }else return nums.size() - l;
            return 0;
        }
        int countNegatives(vector<vector<int>>& grid) {
            int ans = 0;
            for(int i = 0;i < grid.size();i ++)
                ans += merge(grid[i]);
            return ans;
        }
    };
    

    面试题 08.03. 魔术索引

    class Solution {
    public:
        //只需要找到第一个 A[i] = i的元素的下标
        int findMagicIndex(vector<int>& nums) {
           for(int i = 0;i < nums.size();i ++){
               if(i == nums[i])return i;
           }
           return -1;
        }
    };
    
  • 相关阅读:
    有一群志同道合的程序员朋友是怎样的体验?
    hdu1387 模拟队列
    hau 1870 愚人节的礼物(栈)
    hdu1509 优先队列
    hdu1837 看病要排队(优先队列)
    hdu 1237 简单计算器(栈处理)
    hdu1022 模拟栈
    又一个错误的认知!
    jmeter+ant+jenkins 接口自动化测试持续集成(送源码)
    P1197 [JSOI2008]星球大战
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12333095.html
Copyright © 2011-2022 走看看