自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(150)
  • 收藏
  • 关注

原创 19. Remove Nth Node From End of List

双指针,维持两者之间的距离在n,这样第二个指针走到尽头的时候,第一个刚好跟尽头相差n。

2023-11-07 15:39:25 76

原创 17. Letter Combinations of a Phone Number

【代码】17. Letter Combinations of a Phone Number。

2023-11-07 13:56:34 71

原创 16. 3Sum Closest

这题不用去重,其实比之前的要简单。

2023-11-07 12:04:45 122

原创 14. Longest Common Prefix

很聪明的做法,先假设第一个string是Longest Common Prefix, 跟后面的string一个一个对比,不match就删除最后一个字符,until it matches。

2023-11-07 07:58:11 66

原创 11. Container With Most Water

【代码】11. Container With Most Water。

2023-11-07 06:52:37 86

原创 8. String to Integer (atoi)

【代码】8. String to Integer (atoi)

2023-11-07 05:38:15 125

原创 7. Reverse Integer

【代码】7. Reverse Integer。

2023-11-07 02:27:42 102

原创 5. Longest Palindromic Substring

【代码】5. Longest Palindromic Substring。

2023-11-07 02:02:20 138

原创 1762. Buildings With an Ocean View

【代码】1762. Buildings With an Ocean View。

2023-11-06 03:01:36 191

原创 1249. Minimum Remove to Make Valid Parentheses

【代码】1249. Minimum Remove to Make Valid Parentheses。

2023-11-06 02:26:51 176

原创 408. Valid Word Abbreviation

【代码】408. Valid Word Abbreviation。

2023-11-05 09:18:20 605

原创 2. Add Two Numbers

【代码】2. Add Two Numbers。

2023-11-03 09:03:38 84

原创 92. Reverse Linked List II

Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL./** * Definition for s

2017-07-28 05:31:06 194

原创 108. Convert Sorted Array to Binary Search Tree

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {

2017-07-25 14:57:44 163

原创 35. Search Insert Position

当循环结束时,如果没有找到target,那么low一定停target应该插入的位置上,high一定停在恰好比target小的index上。public class Solution { public int searchInsert(int[] nums, int target) { if(nums == null || nums.length == 0){

2017-07-24 14:28:35 145

原创 26. Remove Duplicates from Sorted Array

public class Solution { public int removeDuplicates(int[] nums) { int i=0; for(int j=1; j<nums.length; j++){ if(nums[i] != nums[j]){ i++;

2017-07-24 04:31:25 272

原创 39. Combination Sum I && II

public class Solution { public List> combinationSum(int[] c, int t) { if(c == null || c.length == 0){ return null; } List> result = new ArrayList>(); Li

2017-07-23 13:22:27 182

原创 582. Kill Process

Given n processes, each process has a unique PID (process id) and its PPID (parent process id).Each process only has one parent process, but may have one or more children processes. This is just l

2017-07-08 06:22:57 293

原创 317. Shortest Distance from All Buildings

You want to build a house on an empty land which reaches all buildings in the shortest amount of distance. You can only move up, down, left and right. You are given a 2D grid of values 0, 1 or 2, wh

2017-07-08 03:10:16 188

原创 12. Integer to Roman

Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.要点就是要把900,400等特殊数字的表达方式加上,再按大小依次往下除即可 public String intToRoman(int num) { if(num &...

2017-06-30 08:28:03 154

原创 152. Maximum Product Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the larges

2017-06-30 07:18:23 138

原创 76. Minimum Window Substring

Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BANC".

2017-06-30 07:00:09 146

原创 valid number

Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false public boolean isNumber(String s) { int i = 0, n = s.length(); boolean isNumeric = false;

2017-06-28 14:08:42 143

原创 516. Longest Palindromic Subsequence

Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000.Example 1:Input:"bbbab"Output:4One possible longest palind

2017-06-25 02:31:12 295

原创 72. Edit Distance

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:

2017-06-24 13:50:43 161

原创 515. Find Largest Value in Each Tree Row

You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]/** * Definition f

2017-06-20 13:28:18 190

原创 605. Can Place Flowers

Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.Gi

2017-06-20 13:16:58 207

原创 124. Binary Tree Maximum Path Sum

Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the larges

2017-06-19 12:53:22 139

原创 Convert a Binary Tree to Doubly Linked List

Given a Binary Tree (Bt), convert it to a Doubly Linked List(DLL). The left and right pointers in nodes are to be used as previous and next pointers respectively in converted DLL. The order of nod

2017-06-19 12:39:57 413

原创 152. Maximum Product Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the larges

2017-06-19 12:23:16 120

原创 377. Combination Sum IV

Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]target = 4The pos

2017-06-19 12:19:12 138

原创 88. Merge Sorted Array

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold add

2017-06-19 11:53:00 157

原创 128. Longest Consecutive Sequence

Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2,

2017-06-19 09:53:54 123

原创 Prime Number Combination Product

给一个质数数组,返回所有可能的product,顺序不管比如给 [2,3,5] 返回 [2,3,5,6,10,15,30]数组中的数如果有重复则需要去重,不允许用set。比如给 [2,2,2] 返回 [2,4,8],顺序不用管。public List combinePrimeProduct(int[] primes) { Arrays.sort

2017-06-19 07:43:53 315

原创 43. Multiply Strings

Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.Note:The length of both num1 and num2 is Both num1 and num2 contains only digits

2017-06-19 05:36:45 241

原创 157. Read N Characters Given Read4

The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there is only 3 characters left in the

2017-06-19 05:19:24 172

原创 K closest point to the origin

Give n points on 2-D plane, find the K closest points to origin13 public List KClosest(List input, int k) {14 List res = new LinkedList();15 PriorityQueue pq = new Priority

2017-06-19 03:20:02 797

原创 lowest node's LCA

给一个 二叉树/多叉树 , 求最深节点的最小公共父节点。这题算是对LCA的一个扩展,由给定两个点换成了最深两个点,由二叉树换成多树。难点1. 我们要返回什么?不难看出来, 最后要返回一个node,所以TreeNode 肯定是需要返回的变量之一;另外一个是最长路径或者说最大深度。所以说,每个node往上层返的时候都需要返回这2个变量,一个是当前以node为root

2017-06-17 07:48:27 529

原创 9. Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.public class Solution { public boolean isPalindrome(int x) { if(x < 0){ return false;

2017-06-16 09:15:06 126

原创 234. Palindrome Linked List

Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?求出中点之后反转后半部分的链表,再一一比较。/** * Definition for singly-linked list. * publi

2017-06-16 08:53:35 106

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除