zoukankan      html  css  js  c++  java
  • 4.两个排序数组的中值

    There are two sorted arrays nums1 and nums2 of size m and n respectively.

    Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).

    You may assume nums1 and nums2 cannot be both empty.

    Example 1:

    nums1 = [1, 3]
    nums2 = [2]
    
    The median is 2.0
    

    Example 2:

    nums1 = [1, 2]
    nums2 = [3, 4]
    
    The median is (2 + 3)/2 = 2.5
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    static int lengthOfLongestSubstring(char *s)
    {
        int offset[128];
        int max_len = 0;
        int len = 0;
        int index = 0;
    
        memset(offset, 0xff, sizeof(offset));
        while (*s != '') {
            if (offset[*s] == -1) {
                len++;
            } else {
                if (index - offset[*s] > len) {
                    len++;
                } else {
    	        len = index - offset[*s];
                }
            }
            if (len > max_len) {
                max_len = len;
            }
            offset[*s++] = index++;
        }
    
        return max_len;
    }
    
    int main(int argc, char **argv)
    {
        if (argc != 2) {
            fprintf(stderr, "Usage: ./test string
    ");
            exit(-1);
        }
    
        printf("%d
    ", lengthOfLongestSubstring(argv[1]));
        return 0;
    }
    

      




  • 相关阅读:
    JS----事件
    JS----计时器
    JS----文档对象模型
    JS----基本数据类型
    JS----函数
    JS----数组
    JS----正则表达式
    CSS----盒子模型与浮动
    Web-9月13日随笔
    Web-9月14日随笔
  • 原文地址:https://www.cnblogs.com/still-smile/p/11643691.html
Copyright © 2011-2022 走看看