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;
        }
    };
    
  • 相关阅读:
    黑马day01 xml 的解析方式
    Vijos 1164 曹冲养猪(中国剩余定理)
    HDU 2577 How to Type (线性dp)
    Python中的文本(一)
    [LeetCode] Find Minimum in Rotated Sorted Array
    机器学习算法中怎样选取超參数:学习速率、正则项系数、minibatch size
    java网络基本类使用(一)
    java文档注释主要使用方法
    java数组或集合返回空的问题
    tornado web高级开发项目
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12340699.html
Copyright © 2011-2022 走看看