LeetCode
jasonkwan12
这个作者很懒,什么都没留下…
展开
-
LeetCode 24. Swap Nodes in Pairs Java写法
Given a linked list, swap every two adjacent nodes and return its head.Example:Given 1->2->3->4, you should return the list as 2->1->4->3.Note:Your algorithm should use only constant...原创 2018-04-14 19:53:36 · 144 阅读 · 0 评论 -
Longest Substring Without Repeating Characters java
尺取法public static int lengthOfLongestSubstring(String s) { if(s==null || s.length()==0) return 0; HashSet<Character> set = new HashSet<Character>(); int max = 0...原创 2018-02-06 16:42:35 · 203 阅读 · 0 评论 -
LeetCode no9 Palindrome Number
这个很简单,直接把数字反转过来.特殊情况负数不可能是回文.public boolean isPalindrome(int x) { if(x<0){ return false; } int n=x; int j=0; while(n>0){ int i=n%...原创 2018-03-10 15:11:14 · 124 阅读 · 0 评论 -
LeetCode 6 ZigZag Conversion
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 G...原创 2018-04-05 15:41:53 · 107 阅读 · 0 评论 -
leetcode 10. Regular Expression Matching
这是剑指offer的一道题。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 ent...原创 2018-04-06 17:20:08 · 105 阅读 · 0 评论 -
LeetCode 16. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly...原创 2018-04-07 16:44:31 · 111 阅读 · 0 评论 -
LeetCode-Number of Digit One
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the following number...转载 2018-04-07 20:51:27 · 138 阅读 · 0 评论 -
LeetCode 17. Letter Combinations of a Phone Number IN JAVA
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "23"...原创 2018-04-08 18:11:17 · 123 阅读 · 0 评论 -
LeetCode18. 4Sum Java
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution set m...原创 2018-04-10 00:17:17 · 294 阅读 · 0 评论 -
LeetCode 19. Remove Nth Node From End of List JAVA删除链表倒数第N个
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 en...原创 2018-04-10 19:37:45 · 127 阅读 · 0 评论 -
LeetCode 23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.合并k个已排序的链表成一个排序链表(使用优先队列)class Solution { public ListNode mergeKLists(ListNode[] lists) { ...原创 2018-04-13 10:23:24 · 146 阅读 · 0 评论 -
LeetCode 22. Generate Parentheses JAVA
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())", "...原创 2018-04-11 11:06:09 · 145 阅读 · 0 评论 -
LeetCode 26. Remove Duplicates from Sorted Array
Given a sorted array nums, 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 by modifying...原创 2018-04-18 13:18:26 · 180 阅读 · 0 评论 -
LeetCode 数据库 175. Combine Two Tables
Table: Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName | varchar |+-------------+---------+Perso...原创 2018-04-16 12:53:11 · 211 阅读 · 1 评论 -
LeetCode 28. Implement strStr() Java
水题Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Example 2:Inpu...原创 2018-04-15 19:05:48 · 352 阅读 · 0 评论 -
leetCode 1-twoSun
很久没有刷过题了!!第一次用java写。java为数据结构中的映射定义了一个接口java.util.Map,其中 HashMap:它根据键的hashCode值存储数据,大多数情况下可以直接定位到它的值,因而具有很快的访问速度JAVA:public class Solution { public int[] twoSum(int[] nums, int target) { H...原创 2018-02-04 14:02:19 · 243 阅读 · 0 评论