随笔分类 -  LeetCode Algorithm

摘要:[题目] Given a column title as appear in an Excel sheet, return its corresponding column number. For example: [题目解析] 该题目比较简单,可以理解为一个26进制的数用10进制数表示的过程。 阅读全文
posted @ 2016-11-11 12:37 三刀 阅读(132) 评论(0) 推荐(0)
摘要:[题目] 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. [题目解析] 这 阅读全文
posted @ 2016-11-02 16:16 三刀 阅读(122) 评论(0) 推荐(0)
摘要:[题目] Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime co 阅读全文
posted @ 2016-11-02 16:03 三刀 阅读(124) 评论(0) 推荐(0)
摘要:[题目] Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the 阅读全文
posted @ 2016-11-02 15:41 三刀 阅读(270) 评论(0) 推荐(0)
摘要:[题目] Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a 阅读全文
posted @ 2016-11-02 15:15 三刀 阅读(462) 评论(0) 推荐(0)
摘要:[题目] Given a linked list, determine if it has a cycle in it. [题目解析] 判断一个单链表中是否含有环,这是一个非常常见的面试题目。思路也非常简单,可以定义两个指针,一个快,一个慢,最后慢的追上快的,指向同一个节点,说明有环。 阅读全文
posted @ 2016-10-11 23:02 三刀 阅读(177) 评论(0) 推荐(0)
摘要:[题目] 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 阅读全文
posted @ 2016-09-29 16:55 三刀 阅读(179) 评论(0) 推荐(0)
摘要:[题目] Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [题目解析] 帕斯卡三角,又称杨辉三角,给一个行数,输出杨辉三角,需要结合杨辉三角的性 阅读全文
posted @ 2016-09-10 11:15 三刀 阅读(887) 评论(0) 推荐(0)
摘要:[题目] Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transa 阅读全文
posted @ 2016-09-04 12:57 三刀 阅读(196) 评论(0) 推荐(0)
摘要:[题目] 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 y 阅读全文
posted @ 2016-09-03 22:01 三刀 阅读(209) 评论(0) 推荐(0)
摘要:[题目] 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 lette 阅读全文
posted @ 2016-09-03 15:40 三刀 阅读(421) 评论(0) 推荐(0)
摘要:[题目] Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Fo 阅读全文
posted @ 2016-09-02 16:16 三刀 阅读(124) 评论(0) 推荐(0)
摘要:[题目] Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: Note: You may assum 阅读全文
posted @ 2016-09-01 22:39 三刀 阅读(156) 评论(0) 推荐(0)
摘要:[题目] 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, 阅读全文
posted @ 2016-08-29 11:22 三刀 阅读(92) 评论(0) 推荐(0)
摘要:[题目] 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. [题目 阅读全文
posted @ 2016-08-26 16:32 三刀 阅读(160) 评论(0) 推荐(0)
摘要:[题目] Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in 阅读全文
posted @ 2016-08-26 15:22 三刀 阅读(148) 评论(0) 推荐(0)
摘要:[题目] Determine whether an integer is a palindrome. Do this without extra space. [题目解析] 判断一个给定整数是否为回文数,回文数即121,11411这种正着和反着相同的数字,最小的回文数是0。实现思路可以比较直接,先对 阅读全文
posted @ 2016-08-26 12:09 三刀 阅读(117) 评论(0) 推荐(0)
摘要:[题目] Implement atoi to convert a string to an integer. [题目解析] 该题目比较常见,从LeetCode上看代码通过率却只有13.7%,于是编码提交,反复修改了三四次才完全通过。该题目主要需要考虑各种测试用例的情况,比如"+5"、" 67"、" 阅读全文
posted @ 2016-08-25 21:46 三刀 阅读(163) 评论(0) 推荐(0)
摘要:[题目] Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 [题目解析] 思路比较直接,这里要特别注意的是负数和整数越界的情况。 注意判断是否溢出的时候,是判断的Int 阅读全文
posted @ 2016-08-25 15:17 三刀 阅读(197) 评论(0) 推荐(0)
摘要:[题目] Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. [题目解析] 这道题很关键的是要理解罗马数字的几个主要的代表符号和表示方式 阅读全文
posted @ 2016-08-18 22:27 三刀 阅读(101) 评论(0) 推荐(0)