- 博客(93)
- 资源 (10)
- 收藏
- 关注
原创 python批量修改文件
场景:一个文件夹下有01,02,...不同序号的文件夹,每个文件夹下有一个txt(例如0.25.txt,代表一个参数)。目标:将01下的txt文件用01_camera.txt代替,将参数值(0.25)写入新建的txt文件夹内,最后将原txt(0.25.txt)删除。以下python代码是3.0以上的代码:import os;def main(): rootD
2015-12-04 15:49:40
1157
原创 Binary Tree Preorder Traversal —— Leetcode
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti
2015-09-11 17:04:18
617
原创 Missing Number —— Leetcode
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.For example,Given nums = [0, 1, 3] return 2.Note:Your algorithm shoul
2015-09-11 15:56:56
612
原创 Insertion Sort List —— Leetcode
Sort a linked list using insertion sort.链表与普通的插入排序最大的区别在于:需记录插入结点和被插入结点的前驱,以便快速插入。我的代码运行时间不是最快的:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next
2015-09-10 15:05:44
549
原创 Reverse Words in a String —— Leetcode
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to solve it in-place
2015-09-09 18:29:50
638
原创 Maximum Product Subarray —— Leetcode
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the larges
2015-09-09 10:31:40
499
原创 Letter Combinations of a Phone Number —— Leetcode
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st
2015-09-06 17:20:42
576
原创 3Sum —— Leetcode
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet
2015-09-05 20:51:24
529
原创 Find Peak Element —— Leetcode
A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, i
2015-09-05 15:46:36
490
原创 Largest Number —— Leetcode(sort的妙用)
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve
2015-09-04 16:42:43
662
原创 Two Sum —— Leetcode
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe
2015-09-04 15:19:48
626
原创 Binary Search Tree Iterator —— Leetcode
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next()
2015-09-03 23:09:15
465
原创 Repeated DNA Sequences —— Leetcode(教训,重做)
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri
2015-09-03 21:26:11
508
原创 Container With Most Water —— Leetcode
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, ai) and (i, 0). Fin
2015-09-02 21:04:52
457
原创 Product of Array Except Self —— Leetcode
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O
2015-09-02 19:47:51
452
原创 Different Ways to Add Parentheses —— Leetcode(分治思想)
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, -and *.Example 1I
2015-09-02 16:22:56
781
原创 Number of Islands —— Leetcode(重要的一类题)
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assu
2015-09-01 20:46:40
856
原创 Bitwise AND of Numbers Range
Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.你可以列出一部分连续数的二进制,也许你会发现2^i次方在其中起得作用,也许你想直接从m &到 n,然而,这并没有什么卵用,所得的结果只能是Time Limited。下面的方法,慢慢体会:class Solut
2015-09-01 16:57:39
574
原创 实现atoi——从char*到int的转换
int a2i(const char* str);步骤:1. 判断str的第一位*str是否为'-';2.str++;3.以后转换成int;源码:int a2i(const char *s){ int sign=1; if(*s == '-') sign = -1; s++; int num=0; while(*s) { n
2015-09-01 10:13:22
792
原创 Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]二话不说,上代码:
2015-08-31 21:40:28
497
原创 Longest Substring Without Repeating Characters —— Leetcode
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo
2015-08-08 15:01:23
449
原创 Kth Smallest Element in a BST —— Leetcode
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:What if the
2015-08-04 11:31:35
512
原创 多线程、IO模型、epoll杂谈
1.面向多核的服务器编程时,多线程并不如多进程,因为对于每个进程来说,资源是独立的,切换core的时候无需考虑上下文;而多线程中,每个线程共享资源,在core切换的时候,资源必须从一个core复制到另一个core才能继续运算。换句话说,在cpu多核的情况下,多线程反而不如多进程。2.浏览器开一个页面,页面中很多图片,下载每个图片开一个线程;迅雷下载的时候是把文件分片
2015-08-03 20:00:09
1253
原创 Redis服务器剖析
本文主要分析redis服务器的工作的实现原理,事件,以及redis与memcache处理高并发请求的对比。1. Redis的工作流程首先从宏观上来看一下redis如何处理一个请求,以set key value为例,分为以下4步:(1) client向server发送命令请求set key valueclient会将set key value转换成协议:*
2015-08-03 19:32:50
593
原创 Redis的简单动态字符串——Simple Dynamic String
了解完Redis基本的数据结构之后再来看对象,会发现原来是这样从下到上一步步实现的。Simple Dynamic String(简单动态字符串)(1)SDS的结构struct sdshdr { int len; //记录字符串长度,如图,len=5 int free; //记录未使用的字节数,free=5 char buf[];
2015-07-31 11:40:20
1208
原创 Binary Tree Right Side View —— Leetcode(精巧的方法,第二遍)
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1
2015-05-06 21:55:56
1308
原创 Linked List Cycle —— Leetcode
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?这题大部分刷题书上都有,定义两个指针,一个快一个慢,快的每次走两步,慢的每次走一步,如下情况为有环情况:我的代码还是挺简洁的,如下:/** * D
2015-05-05 20:15:07
515
原创 Plus One —— Leetcode
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.注意点:1. insert的运用 2.
2015-05-04 16:57:48
480
原创 Add Binary —— Leetcode(重做)
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".这题不难,从后往前;难的是如何使代码变得更简洁,参考如下代码:class Solution {public: string addBinary(s
2015-05-04 16:23:23
471
原创 Remove Duplicates from Sorted List —— Leetcode
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.一次通过,自认为方法还是比较简洁的,关于头的定
2015-05-04 10:04:22
486
原创 Merge Sorted Array —— Leetcode
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements fro
2015-05-03 21:15:45
465
原创 Count Primes —— Leetcode
Description:Count the number of prime numbers less than a non-negative number, nclick to show more hints.References:How Many Primes Are There?Sieve of Eratosthenes参考References第二个
2015-05-02 22:17:44
2887
原创 Symmetric Tree —— Leetcode
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f
2015-05-02 16:10:05
518
原创 Same Tree —— Leetcode
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.递归之下,简单的不能
2015-05-01 22:35:07
451
原创 Path Sum —— Leetcode
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 the below binary tree and sum
2015-04-29 20:28:08
504
原创 Merge Two Sorted Lists —— Leetcode(再做一遍)
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.很简单的一道题,为什么做的时候就意识模糊了呢?另外,注意头结点解决边界条件的方法,不需要事先将链表头给he
2015-04-29 20:02:34
396
原创 Happy Number —— Leetcode
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares
2015-04-29 15:33:34
701
原创 Isomorphic Strings —— Leetcode
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with anot
2015-04-29 11:00:28
796
原创 Remove Linked List Elements —— Leetcode
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5链表操作的题目,一般在链表中,对头结点的边界操作
2015-04-29 10:24:58
799
原创 Palindrome Number —— Leetcode(再做一遍)
Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string
2015-04-09 22:23:09
676
Loop-free routing using diffusing computations
2012-05-04
Cisco IP Routing: Packet Forwarding and Intra-domain Routing Protocols
2012-05-03
SQL注射技术总结文档
2012-03-19
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人