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. 10个精选的颜色选择器Javascript脚本及其jQuery插件

     Color picker即颜色选择器使我们在web开发中可能经常用到的组件,今天我们特意精选了10个超酷的颜色选择器实现,其中包括了javascript脚本 实现及其传说中的jQuery插件实现 ...

  2. Jamon

    1.Jamon java 模版引擎 eclipse 插件   http://www.jamon.org/eclipse/updates 2.Jamon 官方网站 http://www.jamon.or ...

  3. Dll的编写 在unity中加载

    1. 在VS中新建Dll项目 2.在头文件中对函数进行声明 extern "C" int _declspec(dllexport) testunity(); 3.在源文件中写函数体 ...

  4. 安卓学习笔记--已root设备应用请求root权限

    网上查到的方法 Process process = null; DataOutputStream os = null; try { String cmd = "chmod 777 " ...

  5. LeetCode(38)-Valid Sudoku

    题目: Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could ...

  6. #cat /proc/meminfo 详解

    $cat /proc/meminfoMemTotal:        2052440 kB //总内存MemFree:           50004 kB //空闲内存Buffers:        ...

  7. rsync+innotify做到同步式更新

    innotify主要功能: 他是内核用于通知用户控件程序文件系统变化的机制. 也就是说,当服务器发生了任何的改动,内核都会知道并通知用户. rssync(做同步的)+innotify做到的就是实时的同 ...

  8. 没人看系列----css 随笔

    目录 没人看系列----css 随笔 没人看系列----html随笔 前言 没什么要说的就是自己总结,学习用的如果想学点什么东西,请绕行. CSS (Cascading Style Sheets)层叠 ...

  9. springboot中使用分页,文件上传,jquery的具体步骤(持续更新)

    分页: pom.xml     加依赖 <dependency> <groupId>com.github.pagehelper</groupId> <arti ...

  10. ubuntu 18.04安装docker以及docker内配置neo4j

    如题 切换到root用户下 apt install docker.io 等啊等,很快,就好了.. 如图 即可使用 如果出现Cannot connect to the Docker daemon at ...