- 博客(156)
- 收藏
- 关注
原创 LoggerFactory打印代码错误日志
使用指定类初始化日志对象在日志输出的时候,可以打印出日志信息所在类如:Logger logger = LoggerFactory.getLogger(com.Book.class); logger.debug("日志信息"); 将会打印出: com.Book : 日志信息public class UserInfoServiceImpl
2017-09-05 10:31:47
2120
原创 木棒拼图
题目:有一个由很多木棒构成的集合,每个木棒有对应的长度,请问能否用集合中的这些木棒以某个顺序首尾相连构成一个面积大于 0 的简单多边形且所有木棒都要用上,简单多边形即不会自交的多边形。初始集合是空的,有两种操作,要么给集合添加一个长度为 L 的木棒,要么删去集合中已经有的某个木棒。每次操作结束后你都需要告知是否能用集合中的这些木棒构成一个简单多边形。输入描述:每组测
2016-12-13 22:33:13
1568
原创 或与加问题
题目:给定 x, k ,求满足 x + y = x | y 的第 k 小的正整数 y 。 | 是二进制的或(or)运算,例如 3 | 5 = 7。比如当 x=5,k=1时返回 2,因为5+1=6 不等于 5|1=5,而 5+2=7 等于 5 | 2 = 7。代码:#include #include using namespace std; i
2016-12-13 22:10:00
382
1
原创 55. 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
2016-04-07 10:03:05
286
原创 98. Validate Binary Search Tree
题目:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node
2016-03-29 10:21:19
263
转载 浅谈C++中指针和引用的区别
指针和引用在C++中很常用,但是对于它们之间的区别很多初学者都不是太熟悉,下面来谈谈他们2者之间的区别和用法。1.指针和引用的定义和性质区别:(1)指针:指针是一个变量,只不过这个变量存储的是一个地址,指向内存的一个存储单元;而引用跟原来的变量实质上是同一个东西,只不过是原变量的一个别名而已。如:int a=1;int *p=&a;int a=1;int &b=a;
2016-03-18 10:05:34
269
原创 209. Minimum Size Subarray Sum
题目:Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the a
2016-03-16 17:08:11
246
原创 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 ↘
2016-03-15 19:53:25
224
原创 326. Power of Three
题目: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?解题思路:case 1:class Solution {public: boo
2016-03-13 19:30:08
281
原创 231. Power of Two
题目:Given an integer, write a function to determine if it is a power of two.解题思路: 将2的幂次方写成二进制形式后,很容易就会发现有一个特点:二进制中只有一个1,并且1后面跟了n个0; 因此问题可以转化为判断1后面是否跟了n个0就可以了。 如果将这个数减去1后会发现,仅有的
2016-03-13 19:09:55
248
原创 313. Super Ugly Number
题目:Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4,
2016-03-08 19:17:54
363
转载 【百度面试题】把数组排成最小的数
问题描述:输入一个正整数数组,将它们连接起来排成一个数,输出能排出的所有数字中最小的一个。例如输入数组{32, 321},则输出这两个能排成的最小数字32132。请给出解决问题的算法,并证明该算法。 思路:先将整数数组转为字符串数组,然后字符串数组进行排序,最后依次输出字符串数组即可。这里注意的是字符串的比较函数需要重新定义,不是比较a和b,而是比较ab与 ba。如果ab b
2016-03-08 16:01:13
206
原创 从1到n整数中1出现的次数
思路:找规律,可以直接根据数n中每一个数字来判断包含1的个数复杂度为O(len),len表示数n包含的数字个数。方法:假设数字为abcde,对于abcde中的每一个数字,可以根据该数字与1的关系,求在该数字对应位置上1出现的次数。具体来说:假设我们要求百位出现1的次数,此时我们可以根据c与1的关系,求出百位1出现的次数。(1)如果c = 0,则1出现
2016-03-08 09:57:58
220
原创 栈的弹入序列问题
题目:输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个弹出序列,但4,3,5,1,2就不可能是该压栈序列的弹出序列。http://www.nowcoder.com/questionTerminal/d77d11405cc7470d82
2016-03-03 08:56:51
337
转载 青蛙跳台阶问题
(1)一只青蛙一次可以跳上 1 级台阶,也可以跳上2 级。求该青蛙跳上一个n 级的台阶总共有多少种跳法。(2)一只青蛙一次可以跳上1级台阶,也可以跳上2 级……它也可以跳上n 级,此时该青蛙跳上一个n级的台阶总共有多少种跳法?分析:1)当n = 1, 只有1中跳法;当n = 2时,有两种跳法;当n = 3 时,有3种跳法;当n = 4时,有5种跳法;当n = 5时,
2016-02-29 11:47:26
261
原创 106. Construct Binary Tree from Inorder and Postorder Traversal
题目:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.解题思路:递归/** * Definition for a binary tree
2016-02-29 09:57:45
229
原创 105. Construct Binary Tree from Preorder and Inorder Traversal
题目:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.解题思路:/** * Definition for a binary tree node.
2016-02-26 20:13:22
286
原创 240. Search a 2D Matrix II
题目: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 in ascending from left to right.Int
2016-02-26 16:25:51
246
原创 74. 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 intege
2016-02-26 16:21:16
253
原创 46. Permutations
题目:Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]
2016-02-26 14:37:33
265
原创 147. Insertion Sort List
题目:Sort a linked list using insertion sort.解题思路:插入排序在链表中运用。可运用递归,比较巧妙。递归版本:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * List
2016-02-26 11:12:58
334
原创 148. Sort List
题目:Sort a linked list in O(n log n) time using constant space complexity.解题思路:使用对链表的归并排序。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *nex
2016-02-26 09:50:12
215
原创 89. Gray Code
题目:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the seq
2016-02-24 16:56:54
227
原创 328. Odd Even Linked List
题目:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to
2016-02-20 16:42:59
222
原创 300. Longest Increasing Subsequence
题目:Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 1
2016-01-06 22:41:18
315
原创 70. Climbing Stairs
题目:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?解题思路:动态规划class So
2016-01-06 21:24:41
224
原创 28. Implement strStr()
题目:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.解题思路:brute-forceclass Solution(object): def strStr(se
2016-01-06 08:50:50
256
原创 36. 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
2016-01-04 20:26:29
217
原创 299. Bulls and Cows
题目:You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide
2015-12-26 22:48:15
211
原创 236. Lowest Common Ancestor of a Binary Tree
题目:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between
2015-12-21 17:15:17
296
原创 235. Lowest Common Ancestor of a Binary Search Tree
题目: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 defin
2015-12-20 22:12:49
218
原创 143. Reorder List
题目:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reord
2015-12-20 22:06:51
233
原创 31、Next Permutation
题目:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest
2015-12-15 22:53:52
248
原创 Excel Sheet Column Number
题目:Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3
2015-12-14 22:12:56
214
原创 Remove Duplicate Letters
题目:Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographica
2015-12-14 11:30:26
320
原创 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"
2015-12-08 22:49:04
210
原创 199、Binary Tree Right Side View
题目:iven 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,
2015-12-08 16:40:03
233
原创 101、Symmetric Tree
题目:iven 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 3B
2015-12-08 11:10:12
229
原创 173、Binary Search Tree Iterator
题目:mplement 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
2015-12-07 16:07:04
209
原创 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.解题思
2015-12-06 22:29:15
208
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人