About Offer
文章平均质量分 59
litoupu
浙大CS硕士,研究方向数据库、数据挖掘、海量数据管理、网络安全。
展开
-
【LeetCode】Maximum Product Subarray
public class Solution { public int maxProduct(int[] A) { if(A==null || A.length ==0)return 0; int len = A.length; int []fn = new int[len];//保存到i位置最大的数 int []zn = n原创 2014-11-11 22:51:49 · 554 阅读 · 0 评论 -
【LeetCode】Intersection of Two Linked Lists
查找两个链表的第一个公共节点,如果两个节点的尾节点相同,肯定存在公共节点 方法: 长的链表开始多走 (h1的数量 - h2的数量)步,然后和短链表同步往下走,遇到的第一个相同的节点就是最早的公共节点 /** * Definition for singly-linked list. * public class ListNode { * int val; * Li原创 2014-11-27 21:55:23 · 7068 阅读 · 0 评论 -
【LeetCode】3Sum
先确定一个数,然后求两个数的和为target,快速算法,编程之美2.12 快速寻找满足条件的两个数 public class Solution { public List> threeSum(int[] num) { Arrays.sort(num); int len = num.length; List> ansList = ne原创 2014-11-27 22:35:03 · 778 阅读 · 0 评论 -
【PAT】1085. Perfect Sequence (25)
题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1085 ti原创 2014-11-05 15:48:03 · 1596 阅读 · 1 评论 -
【LeetCode】Add Two Numbers
题目地址:https://oj.leetcode.com/problems/add-two-numbers/ 链表遍历,注意最高位不为1原创 2014-11-05 23:21:40 · 556 阅读 · 0 评论 -
【LeetCode】Remove Nth Node From End of List
题目地址:https://oj.leetcode.com/problems/remove-nth-node-from-end-of-list/ fa原创 2014-11-06 13:33:36 · 566 阅读 · 0 评论 -
【LeetCode】Remove Duplicates from Sorted List II
题目地址:https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ 方法:原创 2014-11-06 14:02:10 · 617 阅读 · 0 评论 -
【LeetCode】Convert Sorted List to Binary Search Tree
获取中间节点,注意要把链表断开成两个节点,如果节点个数为奇数,则返回最中间的节点,否则返回中间两个节点的前面那个节点 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x;原创 2014-11-28 20:29:12 · 664 阅读 · 0 评论 -
【LeetCode】Search in Rotated Sorted Array II
public class Solution { public boolean binarySearch0(int[] num, int l, int h, int target){ while(l <= h){ int mid = l + (( h - l) >> 1); if(num[mid] > target) h = m原创 2014-12-15 12:52:37 · 795 阅读 · 0 评论 -
【LeetCode】Longest Palindromic Substring
参考:http://blog.csdn.net/soszou/article/details/37312317 public class Solution { public String longestPalindrome(String s) { int len = s.length(); String ans = ""; Stri原创 2014-12-17 09:47:09 · 850 阅读 · 0 评论 -
【LeetCode】Search for a Range
public class Solution { public int binarySearchFirst(int[] A, int target){ int l = 0, h = A.length - 1; int p = -1; while(l <= h){ int mid = l + ((h - l) >> 1);原创 2014-12-02 19:44:28 · 667 阅读 · 0 评论 -
二分查找及变种
//有重复元素找到重复元素最大那个的index,没有找到上界限 public int binarySearchLast(int []a ,int key){ int l = 0, h = a.length - 1, mid; int p = -1; while (l <= h) { mid = l + (h-l) >> 1; if(key > a[mid] && mid原创 2014-11-14 10:45:20 · 1112 阅读 · 0 评论 -
【LeetCode】Copy List with Random Pointer
题目: A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list. 分析: 我们知道如果是简单的copy转载 2014-11-30 16:27:54 · 2470 阅读 · 0 评论 -
【LeetCode】Flatten Binary Tree to Linked List
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { //获取根节点的先原创 2014-12-05 11:09:39 · 613 阅读 · 0 评论 -
【LeetCode】Search in Rotated Sorted Array
public class Solution { public int binarySearch0(int[] num, int l, int h, int target){//普通的二分查找 while(l <= h){ int mid = l + (( h - l) >> 1); if(num[mid] > target)原创 2014-12-15 12:50:05 · 679 阅读 · 0 评论 -
【LeetCode】Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Note: A solution using O(n) space is pretty straight forward. Could you devise a转载 2015-02-27 17:50:50 · 641 阅读 · 0 评论 -
K-th string微软2014在线笔试题
Description Consider a string set that each of them consists of {0, 1} only. All strings in the set have the same number of 0s and 1s. Write a program to find and output the K-th string according原创 2015-04-02 11:35:36 · 1310 阅读 · 0 评论 -
【PAT】1086. Tree Traversals Again (25)
import java.util.Scanner; class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int val) { this.val = val; } } /** * * 结题思路: 根据输入,构建二叉树。 每当一行读入为Push,就在new一个节点给父节点对应的儿子。 每当一行读原创 2014-11-05 11:13:50 · 2775 阅读 · 0 评论 -
【LeetCode】Binary Tree Maximum Path Sum
public class Solution { private static int ans = Integer.MIN_VALUE; /** * 以这棵树为例: 2 / \ 1(黄) -1 / \ / \原创 2014-11-05 11:03:04 · 569 阅读 · 0 评论 -
【LeetCode】Min Stack
需要增加一个保存最小值的栈原创 2014-11-11 19:41:42 · 877 阅读 · 0 评论 -
【LeetCode】Find Minimum in Rotated Sorted Array
诶,二分查找一直是一个痛啊,搞不清楚要不要加1和原创 2014-11-11 20:45:40 · 477 阅读 · 0 评论 -
2014 WAP校园招聘笔试题1
Abstract We are planning an orienteering game. The aim of this game is to arrive at the goal (G) from the start (S) with the shortest distance. However, the players have to pass all the checkpoints原创 2014-11-17 22:33:00 · 2685 阅读 · 0 评论 -
【LeetCode】Sort List
链表的排序,非常实用利用归并排序。原创 2014-11-17 20:35:44 · 536 阅读 · 0 评论 -
【LeetCode】Merge k Sorted Lists
利用优先队列进行合并,要学会使用JDK中的优先队列原创 2014-11-17 21:47:50 · 579 阅读 · 0 评论 -
【LeetCode】Rotate List
把倒数k个节点放到开始节点的前面,注意原创 2014-11-18 19:07:02 · 580 阅读 · 0 评论 -
【LeetCode】Reorder List
利用map 获取节点的 的时候O(l)原创 2014-11-18 20:22:56 · 624 阅读 · 0 评论 -
【LeetCode】Reverse Linked List II
1、要非常熟练翻转链表的代码 2、对于节点原创 2014-11-19 18:47:52 · 830 阅读 · 0 评论 -
【PAT】1025 反转链表(25)basic
/* 1.设¦¨¨置?录?入¨?的Ì?vector足Á?够?大䨮,ê?直¡À接¨®把ã?vector的Ì?index与®?节¨²点Ì?的Ì?address匹£¤配?,ê?这a在¨²节¨²点Ì?数ºy很¨¹少¦¨´的Ì?情¨¦况?下?可¨¦用®?;ê? 2.从䨮给?定¡§头ª¡¤结¨¢点Ì?指?针?开a始º?,ê?顺3序¨°找¨°到Ì?整?个?链¢¡ä,ê?存ä?储ä¡é在¨²vsort原创 2014-11-05 10:39:40 · 2991 阅读 · 0 评论 -
【PAT】1081. Rational Sum (20)
题目地址:http://pat.zju.edu.cn/contests/pat-a-practise/1081 主要熟悉原创 2014-11-05 10:58:10 · 1524 阅读 · 0 评论 -
【LeetCode】Path Sum II
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution {原创 2014-11-05 11:06:56 · 566 阅读 · 0 评论 -
【PAT】1020. Tree Traversals (25)
import java.util.ArrayList; import java.util.LinkedList; import java.util.Scanner; class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int val) { this.val = val; left = null;原创 2014-11-05 11:09:28 · 551 阅读 · 0 评论 -
【LeetCode】Partition List
小于x的所有节点串成一个链表 大于x的所有节点串成一个链表 再将两者拼接起来,注意要链表节点之间的断和链接 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { *原创 2014-11-26 20:00:22 · 636 阅读 · 0 评论 -
【LeetCode】Linked List Cycle II
题目地址:https://oj.leetcode.com/problems/linked-list-cycle-ii/原创 2014-11-05 22:49:33 · 517 阅读 · 0 评论 -
【LeetCode】Remove Duplicates from Sorted List
问题地址:http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/ Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, r原创 2014-04-24 19:37:02 · 720 阅读 · 0 评论 -
【PAT】1015. 德才论 (25) basic
题目地址:http://pat.zju.edu.cn/contests/pat-b-practise/1015 主要熟悉sortshi'yon原创 2014-11-05 10:46:19 · 4169 阅读 · 4 评论 -
【LeetCode】Minimum Size Subarray Sum
采用类似滑动窗口的形式,双指针i,j,复杂度O(n). 与https://leetcode.com/problems/minimum-window-substring/ 这题有点类似 public class Solution { public int minSubArrayLen(int s, int[] nums) { if(nums == null ||原创 2015-05-12 12:37:24 · 2824 阅读 · 0 评论