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. 【AtCoder】ARC067

    ARC067 C - Factors of Factorial 这个直接套公式就是,先求出来每个质因数的指数幂,然后约数个数就是 \((1 + e_{1})(1 + e_{2})(1 + e_{3}) ...

  2. PHP学习之PHP的语法糖

    PHP的语法糖 计算机语言中添加的某种语法,这种语法对语言的功能并没有影响,但是更方便程序员使用.  常见的PHP的语法糖 echo(),print(),die(),isset(),unset(),i ...

  3. Earth Wind and Fire CodeForces - 1148E (构造)

    大意: $n$个石子, 第$i$个石子初始位置$s_i$, 每次操作选两个石子$i,j$, 要求$s_i<s_j$, 任取$d$, 满足$0\le 2d\le s_j-s_i$, 将$s_i,s ...

  4. Java内存管理-探索Java中字符串String(十二)

    做一个积极的人 编码.改bug.提升自己 我有一个乐园,面向编程,春暖花开! 一.初识String类 首先JDK API的介绍: public final class String extends O ...

  5. 关于如何查看 MySQL 信息、查看Oracle 版本

    方法一: 进入mysql cmd, mysql -u root status; 将显示当前mysql的version的各种信息. 方法二: 还是在mysql的cmd下,输入: select versi ...

  6. 【转】在 Delphi 中创建 Linux 守护程序(服务进程)

    转自波哥的译文,必须转过来,太有价值了!原文地址在这里.以下为原文内容: 本文译自 原文链接,语言上做了精炼和排版的变更,以便更简洁明了. Delphi 开始支持 Linux 平台为 Delphi 开 ...

  7. IO 理论 SOCK理论

    IO密集型程序 在程序执行过程中存在大量IO操作,而CPU操作较少,消耗CPU较少,运行效率较低CPU(计算)密集型程序 在程序执行中,CPU运算较多,IO操作相对较少(消耗CPU大,运行速度快)IO ...

  8. 【leetcode】617. Merge Two Binary Trees

    原题 Given two binary trees and imagine that when you put one of them to cover the other, some nodes o ...

  9. 第二章、前端之css

    目录 第二章.前端之css 一.css介绍 二.css语法 三.css几种引入方式 四.css选择器 五.css属性相关 六.css盒子模型 第二章.前端之css 一.css介绍 css(Cascad ...

  10. .net 调用 winapi获取窗口句柄和内容

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...