算法类
文章平均质量分 63
kkkmmmjjjj
这个作者很懒,什么都没留下…
展开
-
15级楼梯,一步最多三级,爬上楼梯可以有多少种走法实现
来源:京东2016算法工程师笔试题思路:上一级有一种方法,上两级有两种方法,上三级有四种方法,上四级的时候最后一步有三种方法,因此上四级的时候三种可能性为最后一步分一 级、两级、三级三种所以为前三种方法的和,依次类推,类似于斐波那契数列。f(1) = f(1)f(2) = f(1)+f(1)f(3) = f(1) + f(2) +1 (三级:三次一级;一次三级;一次原创 2016-12-06 11:15:35 · 4574 阅读 · 0 评论 -
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 read原创 2016-12-30 09:20:34 · 290 阅读 · 0 评论 -
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 input ca原创 2016-12-20 07:19:29 · 239 阅读 · 0 评论 -
Length of Last Word
题目:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A原创 2016-12-31 08:34:47 · 199 阅读 · 0 评论 -
Implement strStr()
题目:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Subscribe to see which companies asked this question思想:原创 2016-12-28 08:54:54 · 214 阅读 · 0 评论 -
Palindrome Number
题目:Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of conver原创 2016-12-21 07:36:10 · 236 阅读 · 0 评论 -
Symmetric Tree
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原创 2017-01-10 08:19:50 · 413 阅读 · 0 评论 -
Construct the Rectangle
For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L原创 2017-02-06 08:09:41 · 302 阅读 · 0 评论 -
Plus One
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.Subscribe to see原创 2017-01-01 09:21:49 · 315 阅读 · 0 评论 -
Island Perimeter
题目:You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is co原创 2017-01-17 07:44:01 · 258 阅读 · 0 评论 -
Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.Credits:Special thanks to @fujiaozhu for adding this转载 2017-01-18 07:39:51 · 265 阅读 · 0 评论 -
Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.原创 2017-01-19 08:53:01 · 204 阅读 · 0 评论 -
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原创 2017-01-20 09:41:36 · 205 阅读 · 0 评论 -
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原创 2017-01-21 14:56:44 · 217 阅读 · 0 评论 -
Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note:The given integer is guaranteed to fit within the range of转载 2017-01-22 07:21:23 · 1747 阅读 · 0 评论 -
Find the Difference
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转载 2017-01-23 07:58:01 · 224 阅读 · 0 评论 -
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 filled转载 2016-12-29 08:24:35 · 253 阅读 · 0 评论 -
Merge Sorted Array
题目:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold ad原创 2017-01-06 08:01:59 · 205 阅读 · 0 评论 -
Remove Element
题目: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 memo原创 2016-12-28 08:24:45 · 218 阅读 · 0 评论 -
求二叉树的最小深度
题目: minimum-depth-of-binary-tree要求:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.原创 2016-12-08 11:17:12 · 1472 阅读 · 0 评论 -
TwoSum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:Given nums =原创 2016-12-16 08:38:06 · 362 阅读 · 0 评论 -
给定你任意正整数,请你输出这个正整数的二进制表示中有几个1。
给定你任意正整数,请你输出这个正整数的二进制表示中有几个1。样例如下:输入:7输出:3#includeusing namespace std;int main(){ int i, n=0; cin >> i; while (i >= 1) { if (i % 2 == 1)原创 2016-12-14 09:12:36 · 1203 阅读 · 0 评论 -
LeetCode:ZigZag Conversion
【版权声明】转载请注明出处:http://www.cnblogs.com/TenosDoIt/p/3738693.html题目链接The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this转载 2016-12-17 12:32:40 · 207 阅读 · 0 评论 -
Implement int sqrt(int x).
题目:Implement int sqrt(int x).Compute and return the square root of x.思路: 我的天呀,一开始拿到这个题目完全没有感想呀,完全不知道啊,做尼玛嗨啊,第一天刷第一题就不会啊,还要把所有题目都刷干净啊,我勒个深深的草啊。网上资料:牛顿迭代法(Newton's method)又称为牛顿-拉夫逊方法(N原创 2016-12-15 08:09:53 · 702 阅读 · 0 评论 -
Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.规则:罗马数字转成整型,首先要知道罗马数字和整型的联系摘自维基百科罗马数字共有7个,即I(1)、V(5)、X(10)、L(50)、C(100原创 2016-12-22 08:11:55 · 275 阅读 · 0 评论 -
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.Subscribe to原创 2017-01-02 09:23:34 · 196 阅读 · 0 评论 -
单链表逆序
2、 单链表逆序 第二个题目是很经典的“单链表逆序”问题。很多公司的面试题库中都有这道题,有的公司明确题目要求不能使用额外的节点存储空间,有的没有明确说明,但是如果面试者使用了额外的节点存储空间做中转,会得到一个比较低的分数。如何在不使用额外存储节点的情况下使一个单链表的所有节点逆序?我们先用迭代循环的思想来分析这个问题,链表的初始状态如图(1)所示:图(1转载 2017-01-02 18:49:23 · 183 阅读 · 0 评论 -
Longest Common Prefix
题目: Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.题意:求所有字符串的最长公共前缀想法:每个字符串都有同样的一个公共前缀,求最长的那个,从字符串容器中取第一个字符串将其每一个字符与其后的字符串依次进行对比即可原创 2016-12-23 07:31:40 · 262 阅读 · 0 评论 -
Remove Nth Node From End of List
题目:Remove Nth Node From End of List例子:Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. Afte原创 2016-12-24 07:53:02 · 229 阅读 · 0 评论 -
Valid Parentheses
题目: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原创 2016-12-25 07:07:17 · 276 阅读 · 0 评论 -
Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c原创 2016-12-19 08:09:52 · 482 阅读 · 0 评论 -
Merge Two Sorted Lists
题目: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.Subscribe to see which companies asked this原创 2016-12-26 07:34:10 · 246 阅读 · 0 评论 -
Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".Subscribe to see which companies asked this question题目:两个表示二进制字符串相加,返回原创 2017-01-04 07:56:18 · 287 阅读 · 0 评论 -
Swap Nodes in Pairs
题目:Swap Nodes in Pairs描述:Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm sh原创 2016-12-27 07:45:03 · 232 阅读 · 0 评论 -
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?Note: Given n will be a posi原创 2017-01-05 08:10:02 · 463 阅读 · 0 评论 -
Remove Duplicates from Sorted Array
题目:Remove Duplicates from Sorted ArrayGiven 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 a原创 2016-12-28 07:58:02 · 222 阅读 · 0 评论 -
Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only o原创 2017-01-24 08:39:39 · 226 阅读 · 0 评论