![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode刷题
ysxforever
此人不懒
展开
-
N皇后
N皇后class Solution { public int totalNQueens(int n) { int[] ans = new int[1]; int[] res = new int[n]; queen(0,n,ans,res); return ans[0]; } public void queen...原创 2020-05-05 21:08:43 · 117 阅读 · 0 评论 -
牛牛找工作
package com.company;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.*;public class Main { static class Job implements Comparable&...原创 2020-04-15 20:54:23 · 124 阅读 · 0 评论 -
二分查找
class Solution { public int search(int[] nums, int target) { int l=0,r=nums.length-1; int mid = (l+r)>>1; while(l<r){ if(nums[mid] < target){ ...原创 2020-04-15 18:21:42 · 107 阅读 · 0 评论 -
牛客--放小球问题
牛客–放小球问题问题描述:n个桶中小球的个数已知,可以操作k次(每次从桶中取出一个球,或者添加一个球),每个桶有规定的最大容量,到最大容量不能放球,桶里没球了也不能拿球.求操作k次后两相邻桶之间的最大差值的平方输入示例: 5, 4, [1,2,3,4,5], [15,15,15,15,15]解释:5个桶 操作4次 桶内的小球分别是1,2,3,4,5 桶的最大容量都是15clas...原创 2020-04-14 21:11:38 · 543 阅读 · 0 评论 -
牛客--一样的水
50%测试案例未超时,其余超时,但是锻炼思路的一种解法import java.util.*;public class Solution { /** * * @param n int整型 水桶的个数 * @param q int整型 询问的次数 * @param a int整型一维数组 n个水桶中初始水的体积 * @param p ...原创 2020-04-13 16:18:21 · 109 阅读 · 0 评论 -
牛客选靓号即拼多多20200410笔试第三题
链接:https://www.nowcoder.com/questionTerminal/005af31a10834b3688911463065ab47d?orderByHotValue=0&mutiTagIds=579&page=2&onlyReference=false来源:牛客网A 国的手机号码由且仅由 N 位十进制数字(0-9)组成。一个手机号码中有至少 K 位...原创 2020-04-12 12:26:01 · 257 阅读 · 1 评论 -
牛客--矩阵最小路径和
import java.util.*;public class Main{ public static void main(String[] args){ Scanner s = new Scanner(System.in); int n = s.nextInt(); int m = s.nextInt(); int[][...原创 2020-04-10 16:46:34 · 136 阅读 · 0 评论 -
牛客--派对的最大快乐值
牛客–派对的最大快乐值java总共花了24M内存用了3.5s,醉了…还是c++猛…import java.util.*;public class Main{ static class Node{ //Integer leader; ArrayList<Integer> workers; int happy; ...原创 2020-04-10 13:10:11 · 541 阅读 · 0 评论 -
leetcode84
单调栈的妙用//普通解法class Solution { public int largestRectangleArea(int[] heights) { if(heights==null||heights.length == 0) return 0; //双指针法 int left = 0; int right = heigh...原创 2020-04-09 11:56:06 · 89 阅读 · 0 评论 -
leetcode72 字符串的编辑距离(难题)
class Solution { public int minDistance(String word1, String word2) { //动态规划:dp[i][j]表示word1中前i个字符串和word2中前j个字符串的编辑距离 int len1 = word1.length(); int len2 = word2.length();...原创 2020-04-06 12:13:29 · 119 阅读 · 0 评论 -
leetcode208字典树
class Trie { Trie[] childNodes = new Trie[27]; /** Initialize your data structure here. */ public Trie() { } /** Inserts a word into the trie. */ public void insert...原创 2020-04-06 10:17:13 · 75 阅读 · 0 评论 -
leetcode51 n皇后问题递归解法
class Solution { public List<List<String>> solveNQueens(int n) { List<List<String>> ret = new ArrayList<>(); char[][] table = new char[n][n]; ...原创 2020-04-03 23:09:12 · 71 阅读 · 0 评论 -
牛客字符串转整数,注意正负号的溢出
牛客字符串转整数import java.util.*;public class Solution { public int StrToInt(String str) { if(str==null||str.equals("")) return 0; int ans = 0; int sign = 1; int i = 0...原创 2020-03-31 09:49:28 · 107 阅读 · 0 评论 -
只用位运算实现两数相加(考虑负数)
只用位运算实现两数相加(考虑负数)//整个程序没有出现+ - * /import java.util.*;public class Solution { public static int Add(int num1,int num2) { int bit1 = 0; int bit2 = 0; int tmp = 0;//当前位计算结果...原创 2020-03-30 21:32:06 · 521 阅读 · 4 评论 -
leetcode59旋转填入数组
class Solution { public int[][] generateMatrix(int n) { int[][] ret = new int[n][n]; int dir = 0;//控制方向0向右,1向下,2向左,3向上 int cnt = 1; int len = n*n; int row =...原创 2020-03-29 20:06:15 · 77 阅读 · 0 评论 -
695岛屿问题
class Solution { public int maxAreaOfIsland(int[][] grid) { int max = 0; int high = grid.length; int width = grid[0].length; for(int i=0;i<high;i++){ ...原创 2020-03-15 09:32:57 · 79 阅读 · 0 评论 -
摩尔投票
摩尔投票class Solution { public List<Integer> majorityElement(int[] nums) { List<Integer> ret = new ArrayList<>(); //给定一个大小为 n 的数组,找出其中所有出现超过 ⌊ n/3 ⌋ 次的元素 //...原创 2020-03-14 10:29:59 · 191 阅读 · 0 评论