自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(76)
  • 收藏
  • 关注

原创 笔试面试题_华为_《简单错误记录》

题目描述开发一个简单错误记录功能小模块,能够记录出错的代码所在的文件名称和行号。 处理:1.记录最多8条错误记录,对相同的错误记录(即文件名称和行号完全匹配)只记录一条,错误计数增加;(文件所在的目录不同,文件名和行号相同也要合并)2.超过16个字符的文件名称,只记录文件的最后有效16个字符;(如果文件名不同,而只是文件名的后16个字符和行号相同,也不要合并)3.输入的文件

2017-04-12 21:43:53 699

转载 最长递增子序列

问题给定一个长度为N的数组,找出一个最长的单调自增子序列(不一定连续,但是顺序不能乱)。例如:给定一个长度为6的数组A{5, 6, 7, 1, 2, 8},则其最长的单调递增子序列为{5,6,7,8},长度为4.解法1:最长公共子序列法这个问题可以转换为最长公共子序列问题。如例子中的数组A{5,6, 7, 1, 2, 8},则我们排序该数组得到数组A‘{1, 2, 5, 6

2017-03-31 23:28:00 384

原创 二叉树的前序、中序、后序遍历—迭代方法

leetcode上的相关题目:前序:https://leetcode.com/problems/binary-tree-preorder-traversal/?tab=Description中序:https://leetcode.com/problems/binary-tree-inorder-traversal/?tab=Description后序:https://leetcode.

2017-02-25 11:35:46 9714

转载 C++拷贝构造函数详解

转自:http://blog.csdn.net/lwbeyond/article/details/6202256/一. 什么是拷贝构造函数首先对于普通类型的对象来说,它们之间的复制是很简单的,例如:[c-sharp] view plain copyint a = 100;  int b = a;   而类对象与普通对象不同,类对象内部结构一般较为复杂

2017-02-23 19:27:52 430

原创 287. Find the Duplicate Number--binary search/快慢指针

Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, fi

2017-02-18 20:55:27 518

转载 二维数组和指向指针的指针

二维数组和指向指针的指针一道面试题引发的问题,首先要知道[]的优先级高于*,题目:char **p,a[6][8]; 问p=a是否会导致程序在以后出现问题?为什么?直接用程序说明:#includevoid main(){    char **p,a[6][8];    p = a;    printf("\n");}

2017-02-18 15:52:15 756

原创 378. Kth Smallest Element in a Sorted Matrix-binary search/heap

Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, not

2017-02-18 11:56:36 299

原创 494. Target Sum-回溯法、DP。

可以使用方法:回溯法、DP。相近的问题:Partition Equal Subset Sum、01背包(1)、01背包(2)。问题描述:You are given a list of non-negative integers, a1, a2, ..., an, and a target,S. Now you have 2 symbols + and -. For ea

2017-02-13 22:30:49 1950

转载 416. Partition Equal Subset Sum子数组和问题

相同子集和分割。与0-1背包相似:01背包(1)、01背包(2)。问题:Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets

2017-02-13 22:10:30 1192 2

原创 LeetCode Maximum Product Subarray_DP_最大子数组

题目:Maximum Product SubarrayFind 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 contig

2017-01-07 16:07:17 337

原创 c/c++中const成员函数的返回值类型

const成员函数又称为访问函数,在const函数体内不能修改成员变量的值。那么对于const函数的返回值呢?结合网上内容,写了一个小的实验代码,class T{public: struct pNode{ int x; int y; }; //不规划的构造 T(){ p = new pNode; p->x = 1; p->y = 2; } //在

2017-01-05 20:31:21 2804 1

原创 最大子序列和问题的解_

问题:有数n1,n2,......,ns。求一个连续的子序列,这个序列的和最大。这个问题有O(n^3)、O(n^2)、O(n*lgn)以及O(n)时间复杂度的解法。下面主要说下O(n*lgn)和O(n)的解法。

2016-12-14 19:47:43 485

原创 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 the stack.top() -- G

2016-12-09 20:25:18 339

原创 204. Count Primes_找n以内的质数_hash

题目以及解法思路答案在原网页上都有。https://leetcode.com/problems/count-primes/Description:Count the number of prime numbers less than a non-negative number, n.Hint:Let's start with a isPrime function.

2016-12-08 20:03:58 342

原创 Implement strStr()--字符串匹配_kmp_bkdHash

Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.两种方法:1)bkdHash2)kmp代码分别如下://bkdHashint strStr(string

2016-12-08 19:08:11 343

原创 20. Valid Parentheses--合法的括号组合(使用stack)

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all vali

2016-11-23 14:39:25 302

转载 找出数组中只出现1(2)次的n个数字

转:http://blog.csdn.net/wujingjing_crystal/article/details/52792286    http://www.cnblogs.com/youxin/p/3349834.html1. 给定一个数组,其中只有一个数出现一次,别的数都出现3次,找出这个数题目描述给定一个数组,其中只有一个数x出现一次,别的数都出现3次,找出这

2016-11-21 21:19:25 487

原创 26. Remove Duplicates from Sorted Array(删除已排序数组中的重复数)-two pointers

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

2016-11-07 20:32:14 277

原创 101. Symmetric Tree--DFS(递归)/BFS(queue+迭代)

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3

2016-11-02 17:44:33 481

原创 437. Path Sum III--dfs + hash + 连续序列的和等于给定的数num

You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, but it

2016-10-27 19:48:22 1613

原创 235. Lowest Common Ancestor of a Binary Search Tree--dfs

Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw

2016-10-24 22:03:36 273

原创 326. Power of Three / 342. Power of Four

Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?代码:class Solution {public: bool isPowerOfThree(i

2016-10-22 20:12:37 269

转载 原码, 反码, 补码 详解

转自:http://www.cnblogs.com/zhangziqiu/archive/2011/03/30/ComputerCode.html本篇文章讲解了计算机的原码, 反码和补码. 并且进行了深入探求了为何要使用反码和补码, 以及更进一步的论证了为何可以用反码, 补码的加法计算原码的减法. 论证部分如有不对的地方请各位牛人帮忙指正! 希望本文对大家学习计算机基础有所帮助!

2016-10-22 16:22:29 244

原创 Maximum XOR of Two Numbers in an Array--异或、字典树

Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.Find the maximum result of ai XOR aj, where 0 ≤ i, j n.Could you do this in O(n) runtime?Example:Input:

2016-10-20 19:55:45 394

原创 387. First Unique Character in a String

Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.Note:

2016-10-13 19:57:16 274

原创 100. Same Tree

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.题目判断两个bina

2016-10-12 21:28:43 228

原创 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 that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value

2016-10-12 19:26:01 206

原创 389. Find the Difference-hash map/XOR

Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was

2016-10-10 20:56:01 325

原创 292. Nim Game

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the

2016-09-29 20:00:39 221

原创 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.重点在于质因数的运用。一个数的阶乘可以写成其所有质数的n次方相乘的形式,例如:10!= 2^8 * 3^4 *

2016-09-28 21:23:20 222

原创 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 ext

2016-09-27 21:23:28 229

转载 c++ list, vector, map, set 区别与用法比较

转自:http://blog.csdn.net/alex_xhl/article/details/37692297List封装了链表,Vector封装了数组, list和vector得最主要的区别在于vector使用连续内存存储的,他支持[]运算符,而list是以链表形式实现的,不支持[]。Vector对于随机访问的速度很快,但是对于插入尤其是在头部插入元素速度很慢,在尾部插入速度

2016-09-26 20:14:19 671

原创 27. Remove Element-two pointers

Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.

2016-09-26 20:09:54 240

转载 桶排序

http://www.cnblogs.com/kkun/archive/2011/11/23/2260267.htmlhttp://www.cnblogs.com/songlee/p/5738142.htmlhttp://blog.csdn.net/houapple/article/details/6480100  桶排序是一种效率很高的排序算法,它的时间复杂度

2016-09-24 20:33:03 286

转载 线性时间排序(计数排序/桶排序/基数排序)

http://www.cnblogs.com/songlee/p/5738142.html线性时间的排序算法   前面已经介绍了几种排序算法,像插入排序(直接插入排序,折半插入排序,希尔排序)、交换排序(冒泡排序,快速排序)、选择排序(简单选择排序,堆排序)、2-路归并排序(见我的另一篇文章:各种内部排序算法的实现)等,这些排序算法都有一个共同的特点,就是基于比较。本文将介

2016-09-24 20:23:24 376

原创 First Missing Positive-计数排序/桶排序

Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant

2016-09-24 20:14:08 261

原创 LeetCode-做题简记

2016年夏天开始,跟着学校的一个leetcode群每天做一题。下面记录下过程中没来得及做的,或者没做好的,或者个人觉得得留意下的题目,以备更好的回顾。菜鸟一个~未做的题目(有空补上):112. Path Sum241. Different Ways to Add Parentheses3. Longest Substring Without Repeating Cha

2016-09-22 20:04:49 226

原创 377. Combination Sum IV-动态规划

Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]target = 4The pos

2016-09-22 19:54:56 1279

原创 Count of Smaller Numbers After Self

You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].Example:

2016-09-21 22:59:16 253

原创 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 that adjacent house

2016-09-13 15:29:05 641

空空如也

空空如也

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

TA关注的人

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