自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(61)
  • 资源 (3)
  • 收藏
  • 关注

原创 [LeetCode] Merge K Sorted Linked Lists

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.算法一:最简单的做法就是先1、2合并,12结果和3合并,123结果和4合并,…,123..k-1结果和k合并。两两合并的时候可以用递归的方法。我们计算一下复杂度。1、2合并,遍历2n个节点

2014-12-29 17:15:53 659

原创 [LeetCode] Roman to Integer

Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.代码:inline int map(const char c) { switch (c) { case 'I': return 1; case 'V':

2014-12-26 18:10:33 513

原创 [LeetCode] Integer to Roman

Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.string intToRoman(int num) { const int radix[] = {1000, 900, 500, 400, 100, 90,

2014-12-26 18:08:26 544

原创 [LeetCode] Mutiply Strings

Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative.用逐位相乘的方法,复杂度是O(m+n),m和n分别是 str1 和 str2 的长度

2014-12-26 15:19:09 583

原创 [LeetCode] Search for a Range

Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found in the

2014-12-26 14:40:50 530

原创 [LeetCode] Search Insert Position

相关问题1:Find a number in the array having least difference with the given number (n)Given a sorted array and a target value, return the index if the target is found. If not, return the index where ...

2014-12-26 14:02:04 549

原创 [LeetCode] Jump Game II

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is to r

2014-12-26 10:04:53 526

原创 [LeetCode] Jump Game I

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you

2014-12-26 09:20:53 429

原创 [LeetCode] Sudoku Solver

Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character '.'. You may assume that there will be only one unique solution.下面的算法用广度搜索的思想,在每一个空的ce

2014-12-25 22:50:20 491

原创 [LeetCode] Rotate Image 旋转图像

You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise).  Follow up: Could you do this in-place?有两种方法。方法一:直接计算法。直接算出旋转前后的对应关系。方法二:间接法。原矩阵到转置矩阵是很容易计

2014-12-24 21:09:03 852

翻译 [LeetCode] Wildcard Matching

Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover

2014-12-23 17:45:12 588

原创 [LeetCode] N-Queen N皇后

相关问题1:八皇后问题,解决思路和代码相关问题2:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutio

2014-12-23 15:02:02 2662

原创 [LeetCode] Permutation II

 Given a collection of numbers that might contain duplicates, return all possible unique permutations. For example, [1,1,2] have the following unique permutations: [1,1,2], [1,2,1], and [2,1,1].思路...

2014-12-23 10:09:08 652

原创 [LeetCode] Anagram

Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case.思路:用一个map保存字符串,如果字符串第一次遇到,那么把这个字符串放入map,如果第2、3、4、...次遇到,那么把第1、2、3、4、...次的字符串放入返回的向量中

2014-12-22 17:32:13 683

原创 [LeetCode] Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, given 1->2->3->3->4->4->5, return 1->2->5. Given 1->1->1->2

2014-12-22 16:14:56 672

原创 [LeetCode] Remove Duplicates From Sorted Array II

Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For example, given sorted array A = [1,1,1,2,2,3], Your function should return length = 5, and A is now [1,1,2,2,3].

2014-12-21 21:48:08 526

原创 [LeetCode] Remove Duplicates From Sorted Array I

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with co

2014-12-20 21:57:20 539

原创 [LeetCode] Valid Sudoku

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille

2014-12-20 21:10:19 683

原创 [LeetCode] Palindrome Partitioning II

Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. For example, given s = "aab", Return 1 sinc

2014-12-18 21:38:51 573

原创 Remove all nodes which don’t lie in any path with sum>= k

Given a binary tree, a complete path is defined as a path from root to a leaf. The sum of all nodes on that path is defined as the sum of that path. Given a number K, you have to remove (prune the tre

2014-12-17 14:08:59 757

翻译 打印距离叶子节点为k的节点 Print nodes that are at distance k from a leaf node

Print all nodes that are at distance k from a leaf nodeGiven a Binary Tree and a positive integer k, print all nodes that are distance k from a leaf node.Here the meaning of distance is different

2014-12-11 05:51:54 890

原创 [LeetCode] Spiral Matrix 旋转打印矩阵

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example, given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You sh

2014-12-10 07:45:34 2031

原创 [LeetCode] k-th permutation 第k个排列

The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3):"123""132""213""231"

2014-12-10 06:38:02 1257

转载 [LeetCode] Rotate Linked List

Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL.Analysis:The idea is to get the whole

2014-12-10 06:15:40 540

原创 [LeetCode] Partition List 分割单链表

给你一个单链表和一个整数x,调整单链表的元素的位置,使得前半部分的值小于x,后半部分的值大于x。下面的算法的思路和单链表快速排序的思路是一样的。ListNode *partition(ListNode *head, int x) { ListNode* slow = head; ListNode* fast = head; while

2014-12-10 05:57:27 740

原创 [LeetCode] Minimum Path Sum in Matrix

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at

2014-12-09 11:07:42 530

原创 [LeetCode] Add Binary 加法

Given two binary strings, return their sum (also a binary string). For example, a = "11", b = "1" Return "100".逐位相加,记录相加的和sum,和进位carry。注意用到了一个有用的函数 to_string() 把整数变成string。string addBinary(strin

2014-12-09 10:41:56 488

转载 [LeetCode] Simplify Path

转自:http://fisherlei.blogspot.com/2013/01/leetcode-simplify-path.htmlGiven an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", => "/home"path = "/a/./b/../..

2014-12-09 07:09:30 501

原创 [LeetCode] Search a 2D Matrix

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each

2014-12-09 06:09:44 458

原创 [LeetCode] Combinations

Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, if n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]

2014-12-09 03:18:01 571

翻译 [LeetCode] Nonrecursive postorder traversal 非递归后续遍历

简单的做法是,用一个栈来保存遍历时的节点,用另外一个栈保存经过节点的次数。下面的算法不需要节点次数的栈。翻译自:http://leetcode.com/2010/10/binary-tree-post-order-traversal.htmlWe use a prev variable to keep track of the previously-traversed no

2014-12-09 01:24:42 916

原创 [LeetCode] Nonrecursive preorder traversal

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].下面给出非递归前序遍历的算法,和非递归中序遍历非常像。

2014-12-08 12:39:27 612

原创 [LeetCode] Search in Rotated Sorted Array

Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in the array return it

2014-12-08 11:47:17 632

原创 [LeetCode] Remove Duplicates from Sorted Linked List 从排序链表中去掉重复值

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.代码很简单,用两个指针,slow和fast,slow

2014-12-08 08:21:42 868

原创 [LeetCode] Merge Sorted Array 归并排序数组

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 from B.

2014-12-08 05:52:11 896

原创 [LeetCode] Number of decoding ways

A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total numb

2014-12-08 04:10:38 554

原创 [LeetCode] 翻转子链表 reverse linked list

Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: Given m, n satisfy the follow

2014-12-08 00:50:20 595

原创 [LeetCode] Restore IP from string 从字符串恢复IP地址

Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given "25525511135", return ["255.255.11.135", "255.255.111.35"]. (Order does

2014-12-07 13:43:58 689

原创 [LeetCode] Interleaving String 交叉字符串

Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given: s1 = "aabcc", s2 = "dbbca", When s3 = "aadbbcbcac", return true. When s3 = "aadbbbaccc", return

2014-12-07 10:16:21 845

原创 [LeetCode] 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(k) extra space?思路:用滚动数组,从后往前加

2014-12-07 08:52:47 542

Monte carlo模拟的Mathematica代码

本文件是用Mathematica代码编写的Monte carlo模拟。 包含均匀分布,指数分布,以及均匀分布在圆和球面上的点。

2010-04-10

网格搜索法--求公切线算法

网格搜索法--求公切线算法。Mathematica程序。

2009-07-08

北邮通信电子电路自测题

这是本人在北邮学习期间,搜集的通信电子电路自测题。老师给的。很有价值。

2009-07-08

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除