- 博客(88)
- 收藏
- 关注
翻译 有关Unicode
作者:Joel Spolsky原文:http://www.joelonsoftware.com/articles/Unicode.html译者注 1:本文并非从原文的开头翻译的,而是从A Historical Perspective开始的。译者注 2:本文的翻译过程中,特地保留了一些技术性词汇的英文原词,因为译者认为牵强地翻译这些词汇是愚蠢的行为。译者注 3:本文并非逐字翻译,一些
2014-08-08 05:24:28
700
原创 [C++11] Move Semantics
1. lvalue和rvalue一切都要从两个古老的概念开始讲起:lvalue和rvalue。先看一段代码:int a = 3;6 = a;这段代码一看就是有问题的,而且显然问题出在了第二行。那么问题到底是什么呢?答案就是:6是一个rvalue,我们不能把rvalue放在赋值操作的左边。这样看来,lvalue和rvalue的意思就呼之欲出了:lvalue是可以放在赋值操作左边的;而r
2014-01-31 07:52:02
1233
原创 [总结] Two's complement
整数在计算机中的表示是使用2's compelment。那2's complement到底是怎么表示一个整数的呢?1. 正整数在2's complement中,一个正整数就是用普通的binary来表示的。但需要注意的是正整数的范围。比如我们的整数是32-bit的,那么正整数的范围是从1到2^31。原因是,在2's complement中,最右端的一位是用来表明正负的,1就是负;0就是正。所
2014-01-26 05:09:26
26089
1
原创 [CTCI] 5.2 Convert Decimal to Binary
问题:Given a (decimal - e.g. 3.72) number that is passed in as a string, print the binary representation.If the number can not be represented accurately in binary, print “ERROR”.分析:我们这里暂时不考虑负数
2014-01-26 01:19:58
1067
原创 [C++] C++中的eplicit关键字
在C++中,构造函数可以用来做隐性的type conversion。比如:#include using namespace std;class A{public: A(); A(int) {cout << "First constructor called" << endl;} A(const char*, int = 0) {cout << "Second construct
2014-01-26 00:24:49
1391
原创 [总结] Bitwise operations
这里总结一下常见的bitwise operations。(C++)1)shift。>是向右shift。这个很简单。需要注意的是补位的问题。如果是向左shift,那么没有问题,补的都是0,换句话说,低位补的都是0;如果是向右shift,那么取决于这个数是signed还是unsigned。如果是signed,那还要取决于最高位是1还是0。如果一个signed的数,最高位是1,那么在向右移动的过
2014-01-25 11:39:05
1994
原创 [CTCI] 4.6 First Common Ancestor for Two Nodes On a Binary tree
问题:Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary sear
2014-01-23 18:36:23
866
原创 [CTCI] Hanoi
问题:In the classic problem of the Towers of Hanoi, you have 3 rods and N disks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size fr
2014-01-19 02:06:47
650
原创 [LeetCode] Binary Tree Maximum Path Sum
问题:Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Ret
2014-01-17 08:18:16
512
原创 [总结] Binary tree traversal
一个binary tree有三种traversal的方式:preorder / inorder / postorder。我们分别来说:1. Preorder所谓preorder,就是处理任何children之前,先处理parent。比如leetcode上,Binary Tree Preorder Traversal 这道题中提供的例子:For example:Given
2014-01-17 06:42:43
858
原创 [LeetCode] 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
2014-01-16 13:54:27
447
原创 [LeetCode] Sort List
问题:Sort a linked list in O(n log n) time using constant space complexity.分析:用divide and conquer。首先遍历一次,找到长度;然后遍历一半,找到中间点;然后在左右两半recursion,然后merge。Time complexity: T(n) = 2T(n/2) + n = O(n
2014-01-11 04:18:14
437
原创 [LeetCode] Maximum Subarray
问题:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−
2014-01-10 13:47:37
431
原创 [LeetCode] Insertion Sort List
问题:Sort a linked list using insertion sort.分析:一般在array上实现的insertion sort,都是向之前的方向移动,找到自己的位置。而现在一个list不能向前移动,所以我们通过从头开始向后走的方式找到每一个node应该在的位置。List的题很考验功底,因为一个不小心哪里细节没注意就会出错。代码:class Solution
2014-01-10 10:49:16
452
原创 [LeetCode] Clone Graph
问题:Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separat
2014-01-10 06:38:50
487
原创 [LeetCode] Copy List with Random Pointer
问题:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.分析:三次遍历,其中:第一次:复制每一
2014-01-08 00:59:20
481
原创 [LeetCode] Distinct Subsequences
问题:Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (c
2014-01-07 09:22:10
482
原创 [LeetCode] Count and Say
问题:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is rea
2014-01-07 08:22:33
382
原创 [LeetCode] String to Integer (atoi)
问题:Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible
2014-01-07 02:01:38
468
原创 [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 partia
2014-01-07 00:58:29
471
原创 [LeetCode] Trapping Rain Water
问题:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3
2014-01-06 23:47:13
949
原创 [LeetCode] Sort Colors
问题:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the
2014-01-06 23:32:43
343
原创 [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 n
2014-01-06 06:16:07
589
原创 [LeetCode] Remove Duplicates from Sorted 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.分析:没什么可说的。代码
2014-01-06 05:37:39
398
原创 [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.Gi
2014-01-06 05:33:08
463
原创 [LeetCode] 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 node ne
2014-01-06 04:19:22
441
原创 [LeetCode] LRU Cache
问题:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of th
2014-01-06 04:17:42
520
原创 [LeetCode] Maximum Depth of Binary Tree
问题:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.分析:简单的一道递归题。代码:class
2014-01-05 08:46:04
395
原创 [LeetCode] Search Insert Position
问题:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in t
2014-01-05 08:42:31
453
原创 [LeetCode] Multiply 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.分析:没有技巧,直接做。代码:class Solut
2014-01-05 07:36:26
416
原创 [LeetCode] Add Two Numbers
问题:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it
2014-01-04 23:42:58
434
原创 [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.Yo
2014-01-04 23:28:09
657
原创 [LeetCode] Jump Game
问题: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.De
2014-01-04 23:21:35
456
原创 [LeetCode] Longest Common Prefix
问题:Write a function to find the longest common prefix string amongst an array of strings.分析:这道题的input是一个vector of strings。首先把这些string中的第一个拿出来作为标准。第一个是谁其实并不重要,它是不是最长的或最短的也不重要,因为common prefix不可能
2014-01-04 12:57:36
614
原创 [LeetCode] Convert Sorted Array to Binary Search Tree
问题:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.分析:简单的一道递归题。代码:class Solution {public: TreeNode *sortedArrayToBST(const vector &num, i
2014-01-04 11:40:20
381
原创 [LeetCode] 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]]分析:没有trick,直接做。
2014-01-04 11:28:49
399
原创 [LeetCode] Path Sum II
问题:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5
2014-01-04 11:21:22
407
原创 [LeetCode] 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 the below binary tree
2014-01-04 11:20:07
363
原创 [LeetCode] Merge Intervals
问题:Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].分析:不难的一道题,但需要注意C++中的comparator的用法。参见这里。
2014-01-04 09:28:03
415
原创 [LeetCode] Maximal Rectangle
问题:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.分析:参考Largest Rectangle in Histogram这道题以及这篇文章。我们面对的这道题可以转化为柱形图,然后用前面这道题
2014-01-04 07:52:44
394
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人