随笔分类 -  leetcode刷题

摘要:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo... 阅读全文
posted @ 2015-04-19 14:27 jasmine_turnsoul 阅读(204) 评论(0) 推荐(0)
摘要:思路:前后两个指针。又一次bug free!(但是速度慢。待我想想有什么更好解法么?或者是 判断可以优化?果真!判断isCharEqual(c1,c2)时,可以优化。不需要判断c1到底是大写还是小写)如下面。 bool isCharEqual(char c1, char c2){ ... 阅读全文
posted @ 2015-04-19 13:05 jasmine_turnsoul 阅读(116) 评论(0) 推荐(0)
摘要:Write a function to find the longest common prefix string amongst an array of strings.思路:这道题其实很简单。只不过一开始我就想复杂了,一看求Longest,就联想到DP。然后又联想到Set来求交并。后来,突然想到... 阅读全文
posted @ 2015-04-19 11:58 jasmine_turnsoul 阅读(131) 评论(0) 推荐(0)
摘要:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu... 阅读全文
posted @ 2015-04-11 18:01 jasmine_turnsoul 阅读(130) 评论(0) 推荐(0)
摘要:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to ... 阅读全文
posted @ 2015-04-11 18:00 jasmine_turnsoul 阅读(157) 评论(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 ... 阅读全文
posted @ 2015-04-01 19:40 jasmine_turnsoul 阅读(135) 评论(0) 推荐(0)
摘要:Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.思路:任何... 阅读全文
posted @ 2015-04-01 19:38 jasmine_turnsoul 阅读(145) 评论(0) 推荐(0)
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-... 阅读全文
posted @ 2015-03-19 23:37 jasmine_turnsoul 阅读(93) 评论(0) 推荐(0)
摘要:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No... 阅读全文
posted @ 2015-03-16 16:49 jasmine_turnsoul 阅读(148) 评论(0) 推荐(0)
摘要:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a... 阅读全文
posted @ 2015-03-16 15:13 jasmine_turnsoul 阅读(176) 评论(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?思路:... 阅读全文
posted @ 2015-03-16 11:23 jasmine_turnsoul 阅读(123) 评论(0) 推荐(0)
摘要:Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After re... 阅读全文
posted @ 2015-03-16 09:45 jasmine_turnsoul 阅读(153) 评论(0) 推荐(0)
摘要:Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor... 阅读全文
posted @ 2015-03-16 09:10 jasmine_turnsoul 阅读(138) 评论(0) 推荐(0)
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.思路:1. 一般做... 阅读全文
posted @ 2015-03-16 08:44 jasmine_turnsoul 阅读(109) 评论(0) 推荐(0)
摘要: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, retu... 阅读全文
posted @ 2015-03-15 19:42 jasmine_turnsoul 阅读(102) 评论(0) 推荐(0)
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?思路:1.两个指针,一个走1步,一个走2步,如果相遇则有环注意: 在使用p->nex... 阅读全文
posted @ 2015-03-15 19:25 jasmine_turnsoul 阅读(92) 评论(0) 推荐(0)
摘要:The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a... 阅读全文
posted @ 2015-03-15 14:46 jasmine_turnsoul 阅读(153) 评论(0) 推荐(0)
摘要:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be ... 阅读全文
posted @ 2015-03-15 11:54 jasmine_turnsoul 阅读(141) 评论(0) 推荐(0)
摘要:Implement pow(x,n).思路:这道题的关键在于 时间。想办法让时间复杂度降低。(但有一点我没想懂,不考虑大小溢出问题么?难道因为是double的原因?待我研究下)解法很巧妙。想了好久,觉得这个解释更合理一点。n = 2k+m ----> xn = (x2)k·xm数n可以拆分成2k+m... 阅读全文
posted @ 2015-03-14 17:02 jasmine_turnsoul 阅读(149) 评论(0) 推荐(0)
摘要:计算机中的数都是以二进制存储,位运算是直接对二进制数进行操作的运算,它的速度非常快。移位运算是其中比较常用的。1. 移位运算分为 逻辑移位 和 算术移位。逻辑移位,是不管往哪边移动,都用0来补齐。算术移位:算术左移,用0补齐。算术右移,用符号位来补齐。注意:将移位区分为逻辑移位和算术移位的原因是,不... 阅读全文
posted @ 2015-03-14 14:52 jasmine_turnsoul 阅读(1427) 评论(0) 推荐(0)