package com.code; import java.util.Arrays; public class Test04_2 { public static int solution(int[] A) { int size = A.length; if(size == 1){ return A[0]==1?1:0; } Arrays.sort(A); for(int i=0;i<size;i++){ if(A[i]!=i+1){ return 0; } } return 1; } publi…
Java – Check if Array contains a certain value?1. String Arrays1.1 Check if a String Array contains a certain value “A”. StringArrayExample1.javapackage com.mkyong.core; import java.util.Arrays;import java.util.List; public class StringArrayExample1…
[问题描述]        假设表达式中允许包含两种括号:圆括号和方括号,其嵌套的顺序随意,如([ ]())或[([ ][ ])]等为正确的匹配,[( ])或([ ]( )或 ( ( ) ) )均为错误的匹配. 现在的问题是,要求检验一个给定表达式中的括弧是否正确匹配? 输入一个只包含圆括号和方括号的字符串,判断字符串中的括号是否匹配,匹配就输出 “OK” ,不匹配就输出“Wrong”. 输入一个字符串:[([][])],输出:OK [输入格式]        输入仅一行字符(字符个数小于255…
Given a binary tree, determine if it is a complete binary tree. Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left…
leetcode - 31. Next Permutation - Medium descrition Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible…
lesson 4: counting elements 1. FrogRiverOne 2. PermCheck 3. MissingInteger 4. MaxCounters lesson 4: counting elements exercise Problem: You are given an integer m (1 <= m <= 1,000,000) and two non-empty, zero-indexed arrays A and B of n integers, a0…
Task description A non-empty zero-indexed array A consisting of N integers is given. A permutation is a sequence containing each element from 1 to N once, and only once. For example, array A such that: A[0] = 4 A[1] = 1 A[2] = 3 A[3] = 2 is a permuta…
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 中位数:如果总数是偶数,那么中位数=中间两个数的平均数:如果总数是奇数,那么中位数=中间那个数的值 思路: O(logx)的算法,就想到二分法.二分法结束的…
1 array变量 Type[] array_virable_name; 2 array对象 2.1 new Type[] array_virable_name = new Type[NUM]; 2.2 initializer {1,2,3,4} 3 array对象存放的内存 无论是new出的数组对象还是通过初始化器得到的数组对象的内存都是在堆上. 3.1 new出的对象 这个对象的内存是在JVM的堆上面的. 3.2 initializer出的对象 也是在JVM的堆上存放的,不是在栈上.通过下面…
数组基础 数组是最基础的数据结构,特点是O(1)时间读取任意下标元素,经常应用于排序(Sort).双指针(Two Pointers).二分查找(Binary Search).动态规划(DP)等算法.顺序访问数组.按下标取值是对数组的常见操作. 相关LeetCode题: 905. Sort Array By Parity  题解 922. Sort Array By Parity II  题解 977. Squares of a Sorted Array  题解 1150. Check If a…