摘要:
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 其实这两道题只是把输入输出反过来而已。不过在写代码之前,还是了解了Roman数字的表示方法。 基本字符 I ... 阅读全文
摘要:
mplement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching sh... 阅读全文
摘要:
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return –321 这道题应该不用详细说了。比较简单。唯一的是要注意特殊值0. public class Solution { public int reverse(int x) { ... 阅读全文
摘要:
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S... 阅读全文
摘要:
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. 首先,所谓回文,其实就是反过来和原来的字符串一样... 阅读全文
摘要:
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}, reorder it t... 阅读全文
摘要:
Given a binary tree, return the preorder traversal of its nodes' values. Given a binary tree, return the postorder traversal of its nodes' values. 对于一棵二叉树的前序和后序遍历来说,应该很熟悉了。在这里采用的是递归的方法。 如果不在IDE里面编辑... 阅读全文
摘要:
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 解题想法: 其实判断一个直线上最好的方法是判断斜率。如果在同一直线上,那么直线上一点与其他点的斜率相同。刚开始的时候利用hashmap记录下了所有相同斜率的点。但是有一点需要注意的是,有时只是平行... 阅读全文
摘要:
题目: 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"... 阅读全文