上一页 1 2 3 4 5 6 7 8 9 ··· 12 下一页
摘要: Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.Soluton:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *mergeKLi... 阅读全文
posted @ 2014-03-14 19:10 xchangcheng 阅读(127) 评论(0) 推荐(0) 编辑
摘要: Given a string, determine if it is a palindrome, considering only alphanumeric(字母与数字) characters and ignoring cases.For example,"A man, a plan, a canal: Panama"is a palindrome.(不区分大小写)"race a car"isnota palindrome.Note:Have you consider that the string might be empty? This is a g 阅读全文
posted @ 2014-03-14 12:48 xchangcheng 阅读(174) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?Solution:首先选取一快一慢两个指针fast与slow: fast每步走两个结点,slow每步走一个结点。若链表有环,则fast将会在某一个时刻追上slow。1. 假设链表有环,且链表长度为n,循环从第k + 1个结点开始(亦即走k步进入循环)2. 让两个指针fast, slow从链表头同时开始遍历 阅读全文
posted @ 2014-03-13 20:14 xchangcheng 阅读(144) 评论(0) 推荐(0) 编辑
摘要: Sort a linked list using insertion sort.Solution:新建链表,逐个插入即可~/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *insertionSortList(ListNode *head) { if(head ... 阅读全文
posted @ 2014-03-13 11:33 xchangcheng 阅读(299) 评论(0) 推荐(0) 编辑
摘要: Evaluate the value of an arithmetic expression inReverse 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" 阅读全文
posted @ 2014-03-12 21:50 xchangcheng 阅读(202) 评论(0) 推荐(0) 编辑
摘要: Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Clarification:What constitutes a word?A sequence of non-space characters constitutes a word.Could the input string contain leading o 阅读全文
posted @ 2014-03-12 21:21 xchangcheng 阅读(245) 评论(0) 推荐(0) 编辑
摘要: There areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[i]of gas to travel from stationito its next station (i+1). You begin the journey with an empty tank at one of the gas stations.Return the starting gas 阅读全文
posted @ 2014-03-12 19:39 xchangcheng 阅读(276) 评论(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 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 @ 2014-03-11 20:37 xchangcheng 阅读(389) 评论(0) 推荐(0) 编辑
摘要: 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 -> 8Solutions:/** * Defin 阅读全文
posted @ 2014-03-11 20:07 xchangcheng 阅读(141) 评论(0) 推荐(0) 编辑
摘要: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to reach the last index in the minimum number of jumps.For example:Given array A =[2,3,1,1,4]The minimum n 阅读全文
posted @ 2014-03-11 19:27 xchangcheng 阅读(701) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 12 下一页