`
cozilla
  • 浏览: 89019 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论
文章列表
题目描述 对一个单链表原地(in-place)排序。即直接对链表结点排序。返回排序后链表的头结点。 链表结点的定义为(请不要在代码中再次定义该结构): C/C++ struct ListNode { int val; ListNode *next; } 渣做法!N^2 ListNode* insert(ListNode* head, ListNode* item) { if (item == NULL) return head; if (head == NULL) { item->next = NULL; return item; ...
Gas Station   AC Rate: 1017/4717 My Submissions   There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You begin the jo ...
Word Break   AC Rate: 2/13 My Submissions   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, givens = "leetcode",dict = ["leet", "code"]. Retur ...
Single Number   AC Rate: 1243/2713 My Submissions   Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?       cla ...
Copy List with Random Pointer   AC Rate: 350/1573 My Submissions   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.     /** * Definition for singly-linked list ...
Path Sum   AC Rate: 872/2770 My Submissions   Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example:Given the below binary tree and sum = 22, 5 / ...
Remove Duplicates from Sorted List   AC Rate: 984/2755 My Submissions   Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given 1->1->2, return 1->2.Given 
Scramble String   AC Rate: 318/1523 My Submissions   Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great": great / \ gr eat / \ / \ g ...
Partition List   AC Rate: 428/1694 My Submissions   Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. For example,G ...
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once. For example,Gi ...
Decode WaysJun 25 '126747 / 26583 A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits, determine the total number of ways to decode it. For example,
Convert Sorted List to Binary Search TreeOct 3 '125768 / 16298 Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.     /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ...
#include <cstdlib> #include <cstdio> #include <vector> #include <map> #include <algorithm> using namespace std; void qfind(vector<int>& a, int k, int left, int right, vector<int>&res ) { if (left > right || k <= 0) return; if (right ...
#include <cstdlib> #include <cstdio> #include <vector> #include <map> #include <algorithm> using namespace std; void reverse(char*s) { if (s == NULL ) return; char *e = s + strlen(s) - 1; while (s < e) swap(*s, *e), s++, e--; } char* add(char* a, char ...
Binary Tree Level Order TraversalSep 29 '125832 / 14746 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,#,#,15,7}, 3 / \ 9 20 / \
Global site tag (gtag.js) - Google Analytics