3.无重复字符的最长子串

/**
* @param {string} s
* @return {number}
*/
var lengthOfLongestSubstring = function(s) {
var ans = [], vis = [], max = 0;
for(var i = 0; i < 256; i++){
vis.push(-1);
}
for(var i = 0; i < s.length; i++){
var t = s[i].charCodeAt() - 0;
if(vis[t] == -1){
vis[t] = i;
ans.push(s[i]);
if(ans.length > max){
max = ans.length;
}
}
else{
var pos = ans.indexOf(s[i]);
for(var j = pos - 1; j >= 0; j--){
vis[ans[j].charCodeAt() - 0] = -1;
}
ans = ans.slice(pos + 1);
ans.push(s[i]);
vis[t] = i;
}
}
return max;
};

4. 寻找两个有序数组的中位数

/**
* @param {number[]} nums1
* @param {number[]} nums2
* @return {number}
*/
var findMedianSortedArrays = function(nums1, nums2) {
if(nums1.length > nums2.length){
var t = nums1;
nums1 = nums2;
nums2 = t;
}
var len = nums1.length + nums2.length;
function find(k,nums1,nums2){
var ans = null;
while(ans === null){
if(k % 2 == 1){
x = Math.floor(k / 2);
if(x == 0)
x = 1;
}else{
x = k / 2;
}
var flag = false;
var temp = [];
if(nums1.length == 0 && nums2.length != 0){
temp = nums2.slice(0,k);
k = 0;
}else if(nums2.length == 0){
temp = nums1.slice(0,k);
k = 0;
}else if(nums1.length < x){
if(nums1[nums1.length - 1] < nums2[x - 1]){
k -= nums1.length;
temp = nums1.slice();
nums1 = [];
}else{
k -= x;
temp = nums2.slice(0,x);
nums2 = nums2.slice(x);
}
}else{
k -= x;
if(nums1[x - 1] < nums2[x - 1]){
temp = nums1.slice(0,x);
nums1 = nums1.slice(x);
}else{
temp = nums2.slice(0,x);
nums2 = nums2.slice(x);
}
}
if(!k){
ans = temp[temp.length - 1];
}
}
return ans;
}
if(len % 2){
return find((len + 1) / 2,nums1,nums2);
}else{
return (function(){
var x1 = nums1.slice(),x2 = nums2.slice();
var sum = find(len / 2,nums1,nums2);
nums1 = x1;
nums2 = x2;
sum += find((len / 2 + 1),nums1,nums2);
return sum / 2;
})();
}
};

Leetcode部分题目整理(Javascript)的更多相关文章

  1. Noip往年题目整理

    Noip往年题目整理 张炳琪 一.历年题目 按时间倒序排序 年份 T1知识点 T2知识点 T3知识点 得分 总体 2016day1 模拟 Lca,树上差分 期望dp 144 挺难的一套题目,偏思维难度 ...

  2. LeetCode高频题目(100)汇总-Java实现

    LeetCode高频题目(100)汇总-Java实现       LeetCode高频题目(100)汇总-Java实现 目录 第01-50题 [Leetcode-easy-1] Two Sum [Le ...

  3. LeetCode算法题目解答汇总(转自四火的唠叨)

    LeetCode算法题目解答汇总 本文转自<四火的唠叨> 只要不是特别忙或者特别不方便,最近一直保持着每天做几道算法题的规律,到后来随着难度的增加,每天做的题目越来越少.我的初衷就是练习, ...

  4. LeetCode SQL题目(第一弹)

    LeetCode SQL题目 注意:Leetcode上的SQL编程题都提供了数据表的架构程序,只需要将它贴入本地数据库即可调试自己编写的程序 不管是MS-SQL Server还是MySQL都需要登陆才 ...

  5. LeetCode题库整理(自学整理)

    1. Two Sum 两数之和       来源:力扣(LeetCode) 题目:给定一个整数数组和一个目标值,找出数组中和为目标值的两个数.你可以假设每个输入只对应一种答案,且同样的元素不能被重复利 ...

  6. NOIp初赛题目整理

    NOIp初赛题目整理 这个 blog 用来整理扶苏准备第一轮 csp 时所做的与 csp 没 有 关 系 的历年 noip-J/S 初赛题目,记录了一些我从不知道的细碎知识点,还有一些憨憨题目,不定期 ...

  7. leetcode二叉树题目总结

    leetcode二叉树题目总结 题目链接:https://leetcode-cn.com/leetbook/detail/data-structure-binary-tree/ 前序遍历(NLR) p ...

  8. Leetcode 题目整理 climbing stairs

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  9. Leetcode 题目整理-3 Palindrome Number & Roman to Integer

    9. Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. clic ...

随机推荐

  1. cdoj 574 High-level ancients dfs序+线段树 每个点所加权值不同

    High-level ancients Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/s ...

  2. 宝塔面板liunx开启ssl域名后无法访问解决方法

    不打开宝塔面板的ssl会不安全,打开了就会提示ssl证书不能使用的错误 如下所示: 您的连接不是私密连接 攻击者可能会试图从 你的ip 窃取您的信息(例如:密码.通讯内容或信用卡信息).了解详情 NE ...

  3. not or and 的优先级是不同的

    not or and 的优先级是不同的: not > and > or 请用最快速度说出答案: not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 an ...

  4. S03_CH01_AXI_DMA_LOOP 环路测试

    S03_CH01_AXI_DMA_LOOP 环路测试 1.1概述 本课程是本季课程里面最简单,也是后面DMA课程的基础,读者务必认真先阅读和学习. 本课程的设计原理分析. 本课程是设计一个最基本的DM ...

  5. PB做的托盘程序(最小化后在左下角显示图标)

    见‘文件’资源

  6. Angular6如何引入jQuery-knob

    Angular6如何引入jQuery-knob 1.概述 Angular6引入jQuery变得异常简单,请参考https://blog.csdn.net/qq_35321405/article/det ...

  7. 设计模式 -- MVC

    MVC 在Web中应用是常见的了,成为基础应用模式. 不好的用法是把业务写在C 中,M只是失血模型. 应该要重M 轻C,业务写在M中,但是这样有问题了.View 会引用Model,那么View会看到M ...

  8. springCloud的feign异常:RequestHeader参数为空时,对key加了大括号{}

    好久没写博客了,今天趁着周末把工作中遇到的问题梳理一下(在这个问题排查过程中,发现自己排查问题的能力还是太弱了,需要加强). 最近在公司springCloud的项目里,通过feign远程调用其他服务, ...

  9. js摄像头

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...

  10. 03 - Mongodb数据查询 | Mongodb

    1.基本查询 ①方法find():查询 db.集合名称.find({条件文档}) ②方法findOne():查询,只返回第一个 db.集合名称.findOne({条件文档}) ③方法pretty(): ...