nodejs 【Node.js基础篇】(三)Node.js创建HTTP服务器 作为一种强大的服务端开发技术,Node.js最本职的工作还是开发Web应用,下面介绍一下如何使用Node.js的核心模块来开发一个HTTP服务器,示例如下: /** * Created by Administrator on 2015/3/25. */ //1.获取内嵌的http模块(提供http服务器和客户端) var http = require('http'); //2.创建HTTP服务器 var server = http.createServer(function(req,res){ if(req.url == '/
nodejs 【Node.js基础篇】(二)Node模块的使用 类似于C++的头文件,Java的引用类,Node.js也有一种将功能拆分、封装、组合的工具,就是模块。 Node.js里的模块的用法与头文件、引用类等有所不同,它使用的是JavaScript的风格,一个模块就是一个对象,可以var一个变量来引用, 具体如下例: //module.js //Node.js创建模块 //module模块里的方法 exports.sayHello = function(){ console.log("床前明月光"); }; //module模块里的变量 exports.hello = "疑是地上霜"; 上述是模块文件,里面定义了一个方法和一个变量, var
nodejs 【Node.js基础篇】(一)Hello World和事件驱动编程 Node.js是基于Google的V8引擎的一个事件驱动I/O服务端JavaScript环境。它在2009年由Ryan Dahl发布,此后,迅速崛起成为一种新型服务端语言。 下面就逐步介绍Node.js。(有关Node.js的安装等过程就不介绍了,另外,建议大家的IDE使用WebStrom,真的很不错。) 和其它语言的入门一样,先得把Hello,World输出来(熟悉的感觉会增强信心) console.log("Hello World"); Node.js是我学过的语言中写“Hello,World”最容易的了,不需要头文件,不需要包,也不需要标签。console是它的一个内嵌对象,log是 console的方法,
leetcode 【LeetCode】198. House Robber 问题描述 You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is
leetcode 【LeetCode】190. Reverse Bits 问题描述 Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000). Follow up: If this function is
leetcode 【LeetCode】189. Rotate Array 问题描述 Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to
leetcode 【LeetCode】172. Factorial Trailing Zeroes 问题描述 Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 阶乘末尾0的个数 分析 偶数乘以5末尾才会出现0,计算1-n出现含有5的个数即可。 代码 class Solution { public: int trailingZeroes(int
leetcode 【LeetCode】171. Excel Sheet Column Number 问题分析 Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C ->
leetcode 【LeetCode】169. Majority Element 问题描述 Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and
leetcode 【LeetCode】168. Excel Sheet Column Title 问题描述 Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA
leetcode 【LeetCode】165. Compare Version Numbers 问题描述 Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0. You may assume that the version strings are non-empty and contain only
leetcode 【LeetCode】160. Intersection of Two Linked Lists 问题描述 Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: A: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b1
leetcode 【LeetCode】155. Min Stack 问题描述 Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. * push(x) -- Push element x onto stack. * pop() -- Removes the element on top of
leetcode 【LeetCode】141. Linked List Cycle 问题描述 Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 代码 class Solution { public: bool hasCycle(ListNode *head) { ListNode* p
leetcode 【LeetCode】136. Single Number 问题描述 Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra
leetcode 【LeetCode】11. Container With Most Water 问题描述 Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i,
leetcode 【LeetCode】125. Valid Palindrome 问题描述 Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is
leetcode 【LeetCode】121. Best Time to Buy and Sell Stock 问题描述 Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie,
leetcode 【LeetCode】119. Pascal's Triangle II 问题描述 Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(
Java Java计算两个日期之间的天数差 public long days(Date d1, Date d2) { long gap = 0; if(d1.before(d2)) { gap = d2.getTime() - d1.getTime(); } else { gap = d1.getTime() - d2.getTime(); } return TimeUnit.DAYS.convert(gap, TimeUnit.
leetcode 【LeetCode】118. Pascal's Triangle 问题描述 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 分析 设f(
leetcode 【LeetCode】112. Path Sum 问题描述 Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given
leetcode 【LeetCode】111. Minimum Depth of Binary Tree 问题描述 Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 二叉树最短路径问题。 问题分析
leetcode 【LeetCode】110. Balanced Binary Tree 问题描述 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every
leetcode 【LeetCode】107. Binary Tree Level Order Traversal II 问题描述 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree [3,