LeetCode
不可不戒
这个作者很懒,什么都没留下…
展开
-
LeetCode 3Sum
/** * 先排序数组.从小开始遍历数组求:-arr[i]=arr[x] + arr[y],y>x>i * 问题变成2Sum * Created by lezg on 16/4/5. */public class Solution { List<List<Integer>> res = new ArrayList<>(); public List<List<Integer>>原创 2016-04-05 21:51:17 · 283 阅读 · 0 评论 -
LeetCode Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may no原创 2016-07-19 16:40:01 · 257 阅读 · 0 评论 -
LeetCode Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example: Given a = 1 and b = 2, return 3./** * 不用 + -实现两个数相加 * 两个数转换为二进制, * 1.各位数不进位,即异或运算原创 2016-07-20 12:37:03 · 362 阅读 · 0 评论 -
LeetCode Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here原创 2016-07-20 15:03:25 · 248 阅读 · 0 评论 -
LeetCode Count and Say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as “one 2, the原创 2016-07-20 15:54:33 · 270 阅读 · 0 评论 -
LeetCode House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses原创 2016-09-11 17:25:29 · 362 阅读 · 0 评论 -
LeetCode House Robber II
After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all houses at this place are arranged in a cir原创 2016-09-11 18:25:47 · 354 阅读 · 0 评论 -
LeetCode 274.H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.According to the definition of h-index on Wikipedia: “A scien原创 2016-09-15 20:23:11 · 371 阅读 · 0 评论 -
Leetcode 102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20原创 2016-09-16 19:28:03 · 390 阅读 · 0 评论 -
LeetCode word-break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s =”leetcode”, dict =[“leet”, “co原创 2016-09-22 08:20:05 · 538 阅读 · 0 评论 -
LeetCode Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack./** * 字符串haystack是否存在子串needle * @param haystack * @param needl原创 2016-07-19 13:20:54 · 251 阅读 · 0 评论 -
LeetCode Valid Parentheses
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 all valid but “原创 2016-04-07 11:00:18 · 270 阅读 · 0 评论 -
LeetCode 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./** * Created by ustc-lezg on 16/4/7. */public class Solu原创 2016-04-07 09:26:34 · 258 阅读 · 0 评论 -
LeetCode Two Sum
/** * 求数组两个数的和等于给定的数 * 先排序数组. * Created by lezg on 16/4/5. */public class Solution { public int[] twoSum(int[] nums, int target) { int len = nums.length; int[] nums_sorted = new原创 2016-04-05 20:43:47 · 301 阅读 · 0 评论 -
LeetCode 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 linke原创 2016-04-06 09:44:04 · 267 阅读 · 0 评论 -
LeetCode Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321/** * 翻转整数,注意溢出. * Created by ustc-lezg on 16/4/6. */public class Solution { public static void main(St原创 2016-04-06 10:07:50 · 397 阅读 · 0 评论 -
LeetCode String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.N原创 2016-04-06 11:12:04 · 321 阅读 · 0 评论 -
LeetCode Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space./** * 判断整数是否为回文, * 负数不是,10整数倍不是.0~9是. * Created by ustc-lezg on 16/4/6. */public class Solution { public boolean isPali原创 2016-04-06 12:56:43 · 289 阅读 · 0 评论 -
LeetCode Container With Most Water
Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lin原创 2016-04-06 13:21:57 · 324 阅读 · 0 评论 -
LeetCode Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings./** * 先排序数组,求所有字符串最长公共前缀, * 只需求排序后的第一个字符串和最后一个字符串公共前缀 * Created by ustc-lezg on 16/4/6. */public class Solutio原创 2016-04-06 16:59:26 · 279 阅读 · 0 评论 -
LeetCode Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.The order原创 2016-04-06 19:02:14 · 302 阅读 · 0 评论 -
LeetCode Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list be原创 2016-04-07 00:00:39 · 332 阅读 · 0 评论 -
LeetCode Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums = [1,原创 2017-01-02 22:27:55 · 637 阅读 · 0 评论