- 博客(22)
- 收藏
- 关注
原创 [leetcode]Intersection of Two Linked Lists[java]找出两个链表的公共节点
题目: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-09-21 17:45:07
321
原创 【leetcode】Valid Parentheses【java】
题目:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are
2015-09-15 22:35:44
266
原创 【leetcode】ZigZag Conversion【java】
题目: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
2015-09-15 15:28:03
272
原创 【leetcode】Roman to Integer【java】
题目:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.给罗马数字,返回真实数字思路:首先给出罗马数字的定义:罗马数字采用七个罗马字母作数字、即Ⅰ(1)、X(10)、C(100)、M
2015-09-13 20:52:56
239
原创 【leetcode】Remove Duplicates from Sorted List【java】
题目:Given a sorted linked list, delete all duplicates such that each element appear only once.给一个已经排好序的链表删除其中的重复结点思路:遍历一遍链表,期间将结点与下一个结点比较,如果值相同则删除代码:
2015-09-13 16:17:53
287
原创 【leetcode】Valid Palindrome【java】
题目: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"
2015-09-08 17:37:11
212
原创 【leetcode】Excel Sheet Column Title【java】
题目:Given a positive integer, return its corresponding column title as appear in an Excel sheet. 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 思路:观察后发现,这些数
2015-09-01 11:49:16
372
原创 【leetcode】Rotate Array【java】
题目:Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].思路:注意注意k可以大于数组的长度,本来我以为不能大于,结果测试的时候第
2015-08-27 17:18:25
240
原创 【leetcode】Remove Linked List Elements【java】
题目:Remove all elements from a linked list of integers that have value val.删除链表中值为val的所有节点思路:设置一个指针节点,用它来判断当前节点的下一个节点是否为目标节点,最后一定要判断当只剩一个节点时,该节点是否为目标节点代码:
2015-08-26 16:53:59
240
原创 【leetcode】Isomorphic Strings【java】
题目: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
2015-08-21 21:34:54
342
原创 【leetcode】Ugly Number【java】
题目:Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is no
2015-08-21 20:35:44
430
原创 【leetcode】Add Digits【java】
题目:Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has
2015-08-16 22:24:13
351
原创 【leetcord】Invert Binary Tree 【java】
题目:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1将二叉树倒置思路:递归的遍历根的左子树和右子树代码:
2015-08-16 21:38:37
435
原创 【leetcode】Rectangle Area【java】
题目 :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 tha
2015-08-13 16:39:20
292
原创 【leetcode】Implement Stack using Queues 【java】
题目:Implement the following operations of a stack using queues.使用队列实现栈思路:pop() empty() top()操作可由队列的poll() peek() isEmpty()函数来完成,push()操作需要在将x添加至队列尾部后将其移植队列头部。补充:offer()方法可插入一个元素,否则返回
2015-08-13 15:47:49
281
原创 【leetcode】Contains Duplicate【java】
题目: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 false if every ele
2015-08-12 22:34:41
260
原创 【leetcode】Power of Two【java】
题目:Given an integer, write a function to determine if it is a power of two.给一个整数判断是否为2的幂次思路:1.首先该数不能为负数。2.考虑到2的0次幂,该数如果为1,也是正确的。代码:还有一种解法2的幂次的数的二进制数中包含1的次数是一次代码:
2015-08-12 20:52:28
216
原创 【leetcode】Palindrome Linked List【java】
题目:Given a singly linked list, determine if it is a palindrome.思路:1.找到中间点2.从中间点开始对链表倒置3.依次比较值是否相同代码
2015-08-12 17:46:33
351
原创 【leetcode】Valid Anagram 【java】
题目:Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.思路一:对比两个字
2015-08-12 15:38:30
258
原创 【leetcode】Remove Element【java】
题目:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new len
2015-08-11 22:32:55
227
原创 【leetcode】Delete Node in a Linked List【java】
题目: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
2015-08-11 21:18:55
255
原创 【leetcode】Remove Duplicates from Sorted Array【java】
题目: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 p
2015-08-11 18:01:21
182
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人