10 examples of 'find largest number in array python' in Python

Every line of 'find largest number in array python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
9def largestnumber(lst):
10 answer = []
11
12 while lst!=[]:
13 max_digit = 0
14 for digit in lst:
15 if IsGreaterOrEqual(digit, max_digit):
16 max_digit = digit
17 answer.append(max_digit)
18 lst.remove(max_digit)
19
20 return answer
4def largestNumber(self, nums):
5 def ncmp(s1, s2):
6 if s1+s2>s2+s1:
7 return 1
8 elif s1+s2==s2+s1:
9 return 0
10 else:
11 return -1
12 nums = sorted([str(num) for num in nums], cmp=ncmp)
13 result = ""
14 while nums:
15 num = nums.pop()
16 result += num
17
18 if result[0] == '0':
19 result = '0'
20 return result
2def splitArray(self, nums, m):
3 """
4 :type nums: List[int]
5 :type m: int
6 :rtype: int
7 """
8 def cut(nums, mid, m):
9 count = 1
10 current_sum = 0
11 for num in nums:
12 current_sum += num
13 if current_sum > mid:
14 count += 1
15 current_sum = num
16 if count > m:
17 return False
18 return True
19
20 low = max(nums)
21 high = sum(nums)
22 while low <= high:
23 mid = (low + high) // 2
24 cuts = cut(nums, mid, m)
25 if cuts:
26 high = mid - 1
27 else:
28 low = mid + 1
29 return low
4def find_max_subarray(numbers):
5 max_till_here = [0]*len(numbers)
6 max_value = 0
7 for i in range(len(numbers)):
8 max_till_here[i] = max(numbers[i], max_till_here[i-1] + numbers[i])
9 max_value = max(max_value, max_till_here[i])
10 return max_value
15def largestNumber(self, nums):
16 sorted_nums = sorted(map(str, nums), key=cmp_to_key(lambda x, y: int(y + x) - int(x + y)))
17 result = ''.join(sorted_nums).lstrip('0')
18 return result or '0'
21def get_missing_number(array):
22 if not array:
23 return 1
24
25 array = get_positive_subset(array)
26 array_len = len(array)
27 # print("array: {}".format(array))
28
29 if not array:
30 return 1
31
32 if max(array) == len(array):
33 return max(array) + 1
34
35 for num in array:
36 current_num = abs(num)
37 if (current_num - 1) < array_len:
38 array[current_num - 1] *= -1
39 # print("mutated_array: {}".format(array))
40
41 for i, num in enumerate(array):
42 if num > 0:
43 return i + 1
2def MaxSumArray(array):
3 maxL, maxR, maxSum = -1,-1,0
4 currL, currR, currSum = 0,0,0
5 for i ,a in enumerate (array):
6 if currSum < 0:
7 currL, currR, currSum = i,i+1,a
8 else:
9 currR , currSum = i+1, currSum + a
10
11 if maxSum < currSum or (maxSum == currSum and currR - currL > maxR - maxL) :
12 maxL ,maxR, maxSum = currL, currR, currSum
13
14 return maxL, maxR, maxSum
6def findKthLargest2(self, nums, k):
7 """
8 :type nums: List[int]
9 :type k: int
10 :rtype: int
11 """
12 arr = nums.copy()
13 arr.sort()
14
15 return arr[-k]
12def largestNumber(self, nums):
13 snums = [str(num) for num in nums]
14 self.quick_sort(0, len(snums)-1, snums)
15 tmp = ''.join(snums).lstrip('0')
16 return tmp if tmp else '0'
25def findLargestNegative(lst, num):
26 lst = [x - num for x in lst]
27 lst = [x for x in lst if x < 0]
28 #lst.sort()
29 if len(lst) > 0:
30 return -lst[-1]
31 else:
32 return 0

Related snippets