2013年9月27日

Word Search

摘要: Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.For example,Givenboard=[ [&q 阅读全文

posted @ 2013-09-27 12:12 Step-BY-Step 阅读(250) 评论(0) 推荐(0) 编辑

Remove Duplicates from Sorted List

摘要: Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3.Solution:稍微修改上一个代码即可,遇到次数多于1的,先输出一个,然后将hashmap中标记一下(这里我就是将其value改为0),后面就不输出它即可。 1 /** 2 * Definition for singly-l 阅读全文

posted @ 2013-09-27 12:05 Step-BY-Step 阅读(200) 评论(0) 推荐(0) 编辑

Remove Duplicates from Sorted List II

摘要: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3.Solution:首先用hashmap计算每个元素出现的次数,然后给list加个头指针,然后遍历链表,将次 阅读全文

posted @ 2013-09-27 07:22 Step-BY-Step 阅读(133) 评论(0) 推荐(0) 编辑

Largest Rectangle in Histogram

摘要: Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of each bar is 1, given height =[2,1,5,6,2,3].The largest rectangle is shown in the shaded area, which has ar 阅读全文

posted @ 2013-09-27 05:27 Step-BY-Step 阅读(374) 评论(0) 推荐(0) 编辑

Scramble String

摘要: Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation ofs1="great": great / \ gr eat / \ / \g r e at / \ a tTo scramble the string, we may choose any non-leaf no... 阅读全文

posted @ 2013-09-27 03:35 Step-BY-Step 阅读(257) 评论(0) 推荐(0) 编辑

导航