# Monthly Archives: January 2015

## [leetcode] Palindrome Number

Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using extra space. You could also try reversing an integer. However, if you […]

## [leetcode] Candy

Candy There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. Children with a higher rating get more candies than their neighbors. What is the […]

## [leetcode] Evaluate Reverse Polish Notation

Evaluate Reverse Polish Notation Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: [“2”, “1”, “+”, “3”, “*”] -> ((2 + 1) * 3) -> 9 [“4”, “13”, “5”, “/”, […]

## [leetcode] Count and Say

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 off as “one 2, then one 1” or 1211. […]

## [leetcode] Letter Combinations of a Phone Number

Letter Combinations of a Phone Number Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit string “23” Output: [“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf”]. Note: Although […]

## [leetcode] Remove Duplicates from Sorted List

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. tag: linked list 简单题，但要注意两点： 1. if 语句条件的判断顺序为从左到右，所以要把判断P为空放在左面先判断，然后再判断p->val == head->val 2. 在函数开始时，把head拷贝给re作为返回元素，head在操作中会被移动。当然，另一个好习惯是把head拷贝成p，然后操作p，最后返回head。 /** * Definition for singly-linked list. * struct ListNode […]

## [leetcode] Excel Sheet Column Title

Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C … 26 -> Z 27 -> AA 28 -> AB Credits: Special thanks to @ifanchu for adding this problem and […]

## [leetcode] Regular Expression Matching

Regular Expression Matching Implement regular expression matching with support for ‘.’ and ‘*’. ‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be: bool isMatch(const char *s, const char *p) Some […]

## [leetcode] Search for a Range

Search for a Range Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm’s runtime complexity must be in the order of O(log n). If the target is not found in the array, return [-1, -1]. For example, Given [5, 7, […]

## [leetcode] Pascal’s Triangle II

Pascal’s Triangle II Given an index k, return the kth row of the Pascal’s triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? tags: array 动态规划中，如果我们只要某一行的规划矩阵的值，我们每必要存下整个矩阵，因为求解某一行的矩阵的值时我们只需要上一行矩阵的值（对于本题来说），所以我们只需记录上一行矩阵的值即可。 class Solution { public: vector<int> getRow(int rowIndex) { vector<int> row; row.push_back(1); if(rowIndex […]