283. Move Zeroes

var moveZeroes = function(nums) {

   var num1=0,num2=1;
while(num1!=num2){
nums.forEach(function(x,y){
if(x===0){
nums.splice(y,1);
nums.push(0);
}
num1 = nums ;
});
nums.forEach(function(x,y){
if(x===0){
nums.splice(y,1);
nums.push(0);
}
num2 = nums ;
});
}
};

这题本身并不难,只是方法要考虑好就最好了,用到方法forEach(),splice(),push()


349. Intersection of Two Arrays

/**
* @param {number[]} nums1
* @param {number[]} nums2
* @return {number[]}
*/
var intersection = function(nums1, nums2) {
var arrt1 = [], i = 0;
nums1.forEach(function(x,y){
nums2.forEach(function(z,v){
if(z==x){
arrt1[i]=x;
i++;
}
}); }); var ret = []; for (var k = 0; k < arrt1.length; k++) {
var item = arrt1[k];
if (ret.indexOf(item) === -1) {
ret.push(item);
}
} return ret; };

这题我的思路是先将两个数组递归遍历,将有重复的部分都存进某个数组,然后数组去重!但是这样在效率上很低,大约击败7%左右的人,仅仅是个可用但是不好用的方法


237. Delete Node in a Linked List

/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} node
* @return {void} Do not return anything, modify node in-place instead.
*/
var deleteNode = function(node) {
node.val=node.next.val;
node.next=node.next.next;
};

【注】一道链表题,题目很简单,不过一开始没读懂。算是复习一下链表。

LeetCode Javascript实现 283. Move Zeroes 349. Intersection of Two Arrays 237. Delete Node in a Linked List的更多相关文章

  1. [LeetCode] 237. Delete Node in a Linked List 解题思路

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

  2. [LeetCode] 237. Delete Node in a Linked List 删除链表的节点

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

  3. 【一天一道LeetCode】#237. Delete Node in a Linked List

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...

  4. LeetCode 237. Delete Node in a Linked List (在链表中删除一个点)

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

  5. 【LeetCode】237. Delete Node in a Linked List 解题报告 (Java&Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 设置当前节点的值为下一个 日期 [LeetCode] ...

  6. [LeetCode&Python] Problem 283. Move Zeroes

    Given an array nums, write a function to move all 0's to the end of it while maintaining the relativ ...

  7. LeetCode Array Easy 283. Move Zeroes

    Description Given an array nums, write a function to move all 0's to the end of it while maintaining ...

  8. LeetCode之237. Delete Node in a Linked List

    ------------------------------------------------ 因为不知道前序是谁,所以只好采用类似于数组实现的列表移动值, 又因为如果当前是最后一个元素了但是已经没 ...

  9. Java for LeetCode 237 Delete Node in a Linked List

    Java实现如下: public class Solution { public void deleteNode(ListNode node) { if(node==null||node.next== ...

随机推荐

  1. Linux管线命令 - cut,grep,sort,uniq,wc,tee,tr,col,join,paste,expand,split,xargs

    在每个管线后面接的第一个数据必定是『命令』喔!而且这个命令必须要能够接受 standard input 的数据才行,这样的命令才可以是为『管线命令』,例如 less, more, head, tail ...

  2. PS 滤镜算法原理——染色玻璃

    %%%% 完成PS 中的染色玻璃滤镜特效 clc; clear all; close all; Image=imread('4.jpg'); Image=double(Image); Gray_Ima ...

  3. ZooKeeper leader election

    Paxos是分布式应用中解决同步问题的核心.作为应用研发工程师,我们总是倾向于使用一种相对简洁的方式实现复杂的算法.ZooKeeper leader election实现就是一个非常好的参考. 其实现 ...

  4. 关于ruby gem无法连接到rubygems.org的解决方案

    RubyGems 镜像 - 淘宝网 为什么有这个? 由于国内网络原因(你懂的),导致 rubygems.org 存放在 Amazon S3 上面的资源文件间歇性连接失败.所以你会与遇到 gem ins ...

  5. javascript内置对象速查(一)

    字符串对象 var str = new String("Hello World"); 可以调用其中的一些方法: str.length str.big 日期对象 var dt = n ...

  6. 恶补web之四:xhtml学习

    xhtml是更严格更纯净的html代码,它与html4.01兼容.xhtml是以xml重构额html4.01 xhtml与2000年1月26日成为w3c标准,w3c将xhtml定义为最新的html版本 ...

  7. OpenShift实战(七):OpenShift定制镜像S2I

    1.基础镜像制作 由于公司的程序是Java开发,上线发布使用的是maven,如果使用openshift自带的S2I,每次都会全量拉取代码(代码比较多,每次全量拉太慢),然后每次打包都会再一次下载mav ...

  8. 多线程编程 NSOperation

     前言 1.NSThread的使用,虽然也可以实现多线程编程,但是需要我们去管理线程的生命周期,还要考虑线程同步.加锁问题,造成一些性能上的开销.我们也可以配合使用NSOperation和NSOper ...

  9. Python版冒泡排序算法

    0 为什么写本文 一方面对经典排序算法冒泡排序进行复习,另一方面通过实际应用来检验python基础知识的掌握情况,包括range函数.len函数.for循环.if语句.函数定义与调用.列表的排序等知识 ...

  10. Install OpenCV on Ubuntu or Debian

    http://milq.github.io/install-OpenCV-ubuntu-debian/转注:就用第一个方法吧,第二个方法的那个sh文件执行失败,因为我价格kurento.org的源,在 ...