leetcode
evolone
这个作者很懒,什么都没留下…
展开
-
leetcode-190&191 Reverse Bits & Number of 1 Bits
一、190 Reverse Bits Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in bina原创 2015-07-08 12:01:39 · 382 阅读 · 0 评论 -
leetcode--83&82 Remove Duplicates from sorted list I&II
Given a sorted linked list, delete all duplicates such that each element appear only once.For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3.去除重复的单链表节点。 时间12ms。 代码:/** *原创 2015-08-11 21:02:26 · 508 阅读 · 0 评论 -
leetcode-26&80 Remove Duplicates from Sorted Array I&II
题干: Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2015-05-12 11:35:38 · 429 阅读 · 0 评论 -
leetcode--160 intersection of two linked list
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: a1 → a2 ↘原创 2015-08-11 11:24:50 · 409 阅读 · 0 评论 -
leetcode-205 Isomorphic Strings
Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a character must be replaced with another chara原创 2015-07-07 21:33:56 · 386 阅读 · 0 评论 -
leetcode-202 Happy Number
Write an algorithm to determine if a number is “happy”.A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of i原创 2015-07-07 15:29:13 · 346 阅读 · 0 评论 -
leetcode-203 Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5题意清楚,主要考察链表指针的使用。 小心头结点和尾节点的处理。 时间36ms。原创 2015-07-07 11:41:00 · 366 阅读 · 0 评论 -
leetcode-231 Power of Two
Given an integer, write a function to determine if it is a power of two. 题目就是求输入整数n,是否为2的幂。 考虑特殊情况,输入为负数、0,1,2,3,4,5. 若为负数和0,false; 1,2,4,true; 3,5,false; 只要n>1,若n%2 != 0;则false; 否则 n = n/2; 时间原创 2015-07-06 16:04:52 · 296 阅读 · 0 评论 -
leetcode-204 Count Primes
Count the number of prime numbers less than a non-negative number, n. 计算小于n的素数的个数。 素数,从2开始,2,3,5,7,11…… 素数定义,除了被1和自身整除外,没有其他因数。 最直接的想法就是从2开始到n的平方根,如果有能整除的,就不是素数。 最直接的往往效率最低。果然,虽然不断剪枝,但是本身的效率低下,再怎么原创 2015-07-06 21:28:30 · 422 阅读 · 0 评论 -
leetcode-206 Reverse Linked List
Reverse a singly linked list. 题意简单,考察对链表的熟练程度。主要注意链表指针的变化。代码如下:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), ne原创 2015-07-06 18:26:33 · 450 阅读 · 0 评论 -
leetcode-223 Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is n原创 2015-07-06 17:26:55 · 421 阅读 · 0 评论 -
leetcode-105&106 Construct Binary Tree from Preorder and Inorder Traversal I&II
Given preorder and inorder traversal of a tree, construct the binary tree.思路简单,但是实现起来就复杂了。思路:发现,前序的第一个为根,然后在中序中找到根,在中序中,根的左边是左子树,右边是右子树。然后递归进入左子树与右子树。可是由于在左子树的时候,坐标会错位,没办法对齐,纠结了很久,还是无法解决。最后求助于强大的百度……发现原创 2015-07-03 19:46:07 · 347 阅读 · 0 评论 -
leetcode-21 Merge Two Sorted Lists
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.题目很简单,就是考察队链表插入的熟悉程度。 12ms。 代码:/** * Definition for singl原创 2015-07-03 21:55:28 · 328 阅读 · 0 评论 -
leetcode--217&219&220 Contains Duplicate(重复)I&II&III
一、217 Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return原创 2015-06-30 20:24:54 · 658 阅读 · 0 评论 -
leetcode-10 Regular Expression Matching
Implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should cover the entire input string原创 2015-07-01 20:05:52 · 400 阅读 · 0 评论 -
leetcode --237 delete node in a linked list
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, t原创 2015-08-05 10:29:50 · 338 阅读 · 0 评论