随笔分类 - LeetCode Algorithm
摘要:[题目] Given a column title as appear in an Excel sheet, return its corresponding column number. For example: [题目解析] 该题目比较简单,可以理解为一个26进制的数用10进制数表示的过程。
阅读全文
摘要:[题目] 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. [题目解析] 这
阅读全文
摘要:[题目] 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
阅读全文
摘要:[题目] 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
阅读全文
摘要:[题目] 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
阅读全文
摘要:[题目] Given a linked list, determine if it has a cycle in it. [题目解析] 判断一个单链表中是否含有环,这是一个非常常见的面试题目。思路也非常简单,可以定义两个指针,一个快,一个慢,最后慢的追上快的,指向同一个节点,说明有环。
阅读全文
摘要:[题目] 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
阅读全文
摘要:[题目] Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [题目解析] 帕斯卡三角,又称杨辉三角,给一个行数,输出杨辉三角,需要结合杨辉三角的性
阅读全文
摘要:[题目] 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
阅读全文
摘要:[题目] 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
阅读全文
摘要:[题目] 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
阅读全文
摘要:[题目] 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
阅读全文
摘要:[题目] 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
阅读全文
摘要:[题目] 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,
阅读全文
摘要:[题目] 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. [题目
阅读全文
摘要:[题目] Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in
阅读全文
摘要:[题目] Determine whether an integer is a palindrome. Do this without extra space. [题目解析] 判断一个给定整数是否为回文数,回文数即121,11411这种正着和反着相同的数字,最小的回文数是0。实现思路可以比较直接,先对
阅读全文
摘要:[题目] Implement atoi to convert a string to an integer. [题目解析] 该题目比较常见,从LeetCode上看代码通过率却只有13.7%,于是编码提交,反复修改了三四次才完全通过。该题目主要需要考虑各种测试用例的情况,比如"+5"、" 67"、"
阅读全文
摘要:[题目] Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 [题目解析] 思路比较直接,这里要特别注意的是负数和整数越界的情况。 注意判断是否溢出的时候,是判断的Int
阅读全文
摘要:[题目] Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. [题目解析] 这道题很关键的是要理解罗马数字的几个主要的代表符号和表示方式
阅读全文

浙公网安备 33010602011771号