zoukankan      html  css  js  c++  java
  • 每日算法

    每日算法

    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.20


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

    167. 两数之和 II - 输入有序数组

    class Solution {
    public:
        vector<int> twoSum(vector<int>& numbers, int target) {
            vector<int> ans;
            for(int i = 0;i < numbers.size(); i ++)
            {
                int x = numbers[i];
                int l = 0,r = numbers.size() - 1;
                while(l < r)
                {
                    int mid = l + r >> 1; 
                    if(numbers[mid] + x >= target)r = mid;
                    else l = mid + 1;
                }
                if(numbers[l] + x == target && i != l){
                    if(l > i){
                        ans.push_back(i+1);ans.push_back(l+1);
                    }else {
                        ans.push_back(l+1);ans.push_back(i+1);
                    }
                    break;
                }
            }
            return ans;
        }
    };
    

    278. 第一个错误的版本

    二分 找到第一个为true得数字

    // Forward declaration of isBadVersion API.
    bool isBadVersion(int version);
    
    class Solution {
    public:
        int firstBadVersion(int n) {
            long long l = 0, r = n;
            while(l < r)
            {
                long long mid = l + r >> 1;
                if(isBadVersion(mid) == true)r = mid;
                else l = mid + 1;
            }
            return l;
        }
    };
    
  • 相关阅读:
    2019牛客暑期多校训练营(第三场)B题、H题
    2019牛客暑期多校训练营(第四场)k题、j题
    Manacher算法 & Palindrome
    HDU 3336——Count the string
    判断一个点是否在三角形内
    P1052 过河
    P1353 [USACO08JAN]跑步Running
    hdu 1686 Oulipo
    Cyclic Nacklace HDU
    高精地图技术分析
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12340699.html
Copyright © 2011-2022 走看看