上一页 1 2 3 4 5 6 7 8 9 10 ··· 17 下一页

2013年11月11日

ZigZag Conversion

摘要: 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 NA P L S I I GY I RAnd then read line by line:"PAHNAPLSIIGYIR"Write the code that will take a string and 阅读全文

posted @ 2013-11-11 20:33 waruzhi 阅读(210) 评论(0) 推荐(0) 编辑

Anagrams

摘要: Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.思路:最开始不理解题意。其实题目的意思是看原数组里面是否有些字符串是互相可以通过改变字母顺序转换的。这样的话使用一个map,字符串作为key值,保存下标。遍历原数组,每访问一个字符串,先对它进行排序,看map是否有它,如果有的话,就存入结果vector,否则存入map。注意需要一个标记来记录第一个放入map的字符串是否放入结果,放入之前是字符串的下标,放入后改为-1.代码 阅读全文

posted @ 2013-11-11 19:57 waruzhi 阅读(198) 评论(0) 推荐(0) 编辑

Reverse Nodes in k-Group

摘要: Given a linked list, reverse the nodes of a linked listkat a time and return its modified list.If the number of nodes is not a multiple ofkthen left-out nodes in the end should remain as it is.You may not alter the values in the nodes, only nodes itself may be changed.Only constant memory is allowed 阅读全文

posted @ 2013-11-11 19:30 waruzhi 阅读(124) 评论(0) 推荐(0) 编辑

Add Two Numbers

摘要: You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.Input:(2 -> 4 -> 3) + (5 -> 6 -> 4)Output:7 -> 0 -> 8代码: 1 ListNode *addTw 阅读全文

posted @ 2013-11-11 17:05 waruzhi 阅读(146) 评论(0) 推荐(0) 编辑

Longest Substring Without Repeating Characters

摘要: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo... 阅读全文

posted @ 2013-11-11 16:21 waruzhi 阅读(181) 评论(0) 推荐(0) 编辑

Distinct Subsequences

摘要: Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie,"ACE" 阅读全文

posted @ 2013-11-11 11:31 waruzhi 阅读(159) 评论(0) 推荐(0) 编辑

2013年11月10日

Sqrt(x)

摘要: Implementint sqrt(int x).Compute and return the square root ofx.思路:使用二分。为了减少搜索范围,将上界定位最大的整数的开方,也避免了整数越界的情况。另外在第9行分别先除2再相加,也是避免越界。代码: 1 int border(int a){ 2 if(a x){15 return sqrt(left, middle, x);16 }17 else18 return middle;19 }20 int sqrt... 阅读全文

posted @ 2013-11-10 00:51 waruzhi 阅读(287) 评论(0) 推荐(0) 编辑

2013年11月9日

Best Time to Buy and Sell Stock III

摘要: Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwotransactions.Note:You may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).思路:将vector分 阅读全文

posted @ 2013-11-09 23:47 waruzhi 阅读(164) 评论(0) 推荐(0) 编辑

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", &q 阅读全文

posted @ 2013-11-09 21:53 waruzhi 阅读(161) 评论(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.思路:指针操作代码: 1 ListNode *deleteDuplicates(ListNode *hea 阅读全文

posted @ 2013-11-09 21:33 waruzhi 阅读(161) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 9 10 ··· 17 下一页

导航