2014年5月22日
摘要: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 其实这两道题只是把输入输出反过来而已。不过在写代码之前,还是了解了Roman数字的表示方法。 基本字符 I ... 阅读全文
posted @ 2014-05-22 15:05 JessiaDing 阅读(103) 评论(0) 推荐(0) 编辑
  2014年5月20日
摘要: mplement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching sh... 阅读全文
posted @ 2014-05-20 14:52 JessiaDing 阅读(345) 评论(0) 推荐(0) 编辑
  2014年5月19日
摘要: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return –321 这道题应该不用详细说了。比较简单。唯一的是要注意特殊值0. public class Solution { public int reverse(int x) { ... 阅读全文
posted @ 2014-05-19 14:04 JessiaDing 阅读(88) 评论(0) 推荐(0) 编辑
摘要: 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... 阅读全文
posted @ 2014-05-19 13:50 JessiaDing 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 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. 首先,所谓回文,其实就是反过来和原来的字符串一样... 阅读全文
posted @ 2014-05-19 12:30 JessiaDing 阅读(107) 评论(0) 推荐(0) 编辑
  2014年5月8日
摘要: 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... 阅读全文
posted @ 2014-05-08 22:53 JessiaDing 阅读(107) 评论(0) 推荐(0) 编辑
摘要: 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里面编辑... 阅读全文
posted @ 2014-05-08 15:32 JessiaDing 阅读(131) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list using insertion sort. 链表的插入排序,其实有2种特殊情况: 1、插入的值插入到已排序的末尾。 2、插入的值插入到已排序的最前端。 主要设置了3个指针。 1、pStart是已排序链表的开始位置。 2、pInsert是待插入的位置。 3、pEnd是下一个等待排序的位置。 key:每个已排序的链表最后的Node的next指针为n... 阅读全文
posted @ 2014-05-08 13:30 JessiaDing 阅读(139) 评论(0) 推荐(0) 编辑
  2014年5月7日
摘要: Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. 解题想法: 其实判断一个直线上最好的方法是判断斜率。如果在同一直线上,那么直线上一点与其他点的斜率相同。刚开始的时候利用hashmap记录下了所有相同斜率的点。但是有一点需要注意的是,有时只是平行... 阅读全文
posted @ 2014-05-07 16:14 JessiaDing 阅读(126) 评论(0) 推荐(0) 编辑
  2014年5月6日
摘要: 题目: 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"... 阅读全文
posted @ 2014-05-06 13:26 JessiaDing 阅读(161) 评论(0) 推荐(0) 编辑